Last active
          December 28, 2018 16:40 
        
      - 
      
- 
        Save tabvn/54611f65d0df5656bab1393944f09483 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <iostream> | |
| #include <vector> | |
| #include <algorithm> | |
| #include <string> | |
| using namespace std; | |
| struct Seq | |
| { | |
| char c; | |
| long long length; | |
| }; | |
| vector<Seq> v; | |
| Seq seq; | |
| int main(){ | |
| int n; | |
| char ch,lastChar; | |
| cin >> n; | |
| seq.length = 0; | |
| for (int i = 0; i < n; ++i){ | |
| cin >> ch; | |
| if(i ==0){ | |
| seq.c = ch; | |
| } | |
| if(i != 0 && lastChar != ch){ | |
| v.push_back(seq); | |
| seq.c = ch; | |
| seq.length = 0; | |
| } | |
| seq.length ++; | |
| lastChar = ch; | |
| if(i == n-1){ | |
| v.push_back(seq); | |
| } | |
| } | |
| int lastIndex = (int)v.size() -1; | |
| long long total = 3; | |
| if(v[0].c == v[lastIndex].c){ | |
| total += 1; | |
| } | |
| total += v[lastIndex].length -1; | |
| total += v[0].length -1; | |
| cout << (total % 998244353); | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment