# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40946 | 2018-02-09T23:39:27 Z | wzy | Difference (POI11_roz) | C++14 | 833 ms | 16684 KB |
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define pii pair<int,int> #define ieps (int) 1e6 #define eps (int) 1e9 #define mp make_pair #define pb push_back vector<int> hist[27]; int n; string s; int ansj = 0; void solve(int pos , int neg){ int cnta = 0 , cntb = 0 , curr = 0 , leftp = 0 , foineg = false; for(int i = 0 ; i < hist[pos].size() + hist[neg].size() ; i++){ if(cnta == hist[pos].size()){ if(!foineg){ ansj = max(ansj , curr - 1); } return; } else if(cntb == hist[neg].size()){ if(!foineg){ break; } while(cnta++ <hist[pos].size()){ curr++; } if(foineg)ansj = max(ansj , curr); break; } else{ if(hist[pos][cnta] < hist[neg][cntb]){ curr++; cnta++; if(foineg) ansj = max(ansj , curr); } else{ cntb++; if(curr - 1 >=0){ curr--; foineg = true; if(foineg) ansj = max(ansj , curr); } else{ foineg = false; curr = 0; } } } } return; } int32_t main(){ scanf("%d" , &n); s.resize(n); scanf("%s" , &s[0]); for(int i = 0 ; i < n;i++){ hist[s[i] - 'a'].pb(i); } for(char i = 'a' ; i <= 'z' ; i++){ for(char j = 'a' ; j <= 'z'; j++){ if(i == j) continue; solve(i-'a' , j-'a'); } } for(int i = 0 ; i < n;i++){ hist[s[i] - 'a'].clear(); } reverse(s.begin() , s.end()); for(int i = 0 ; i < n;i++){ hist[s[i] - 'a'].pb(i); } for(char i = 'a' ; i <= 'z' ; i++){ for(char j = 'a' ; j <= 'z'; j++){ if(i == j) continue; solve(i-'a' , j-'a'); } } printf("%d\n" , ansj); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 248 KB | Output is correct |
2 | Correct | 2 ms | 356 KB | Output is correct |
3 | Correct | 2 ms | 464 KB | Output is correct |
4 | Correct | 1 ms | 464 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 616 KB | Output is correct |
2 | Correct | 2 ms | 616 KB | Output is correct |
3 | Correct | 2 ms | 644 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 684 KB | Output is correct |
2 | Correct | 2 ms | 684 KB | Output is correct |
3 | Correct | 2 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 740 KB | Output is correct |
2 | Correct | 2 ms | 740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 748 KB | Output is correct |
2 | Correct | 2 ms | 748 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 78 ms | 1404 KB | Output is correct |
2 | Correct | 2 ms | 1404 KB | Output is correct |
3 | Correct | 5 ms | 1404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 764 ms | 7884 KB | Output is correct |
2 | Correct | 2 ms | 7884 KB | Output is correct |
3 | Correct | 381 ms | 7884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 833 ms | 9500 KB | Output is correct |
2 | Correct | 555 ms | 9572 KB | Output is correct |
3 | Correct | 128 ms | 10020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 773 ms | 12348 KB | Output is correct |
2 | Correct | 80 ms | 12572 KB | Output is correct |
3 | Correct | 44 ms | 13472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 748 ms | 14800 KB | Output is correct |
2 | Correct | 52 ms | 15176 KB | Output is correct |
3 | Correct | 140 ms | 16684 KB | Output is correct |