Submission #696335

#TimeUsernameProblemLanguageResultExecution timeMemory
696335dongliu0426Difference (POI11_roz)C++17
90 / 100
620 ms33672 KiB
#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <iostream> #include <vector> using namespace std; const int N = 1e6; int main() { int n; scanf("%d", &n); static char s[N]; scanf("%s", s); static vector<int> u[N]; for (int i = 0; i < n; i++) u[s[i] - 'a'].push_back(i); int ans = 0; for (int i = 0; i < 26; i++) for (int j = 0; j < 26; j++) { if (i == j) continue; static int t[N + 1]; int m = 0, l = 0, r = 0; while (l < (int) u[i].size() || r < (int) u[j].size()) if (l == (int) u[i].size()) t[++m] = -1, r++; else if (r == (int) u[j].size()) t[++m] = +1, l++; else if (u[i][l] < u[j][r]) t[++m] = +1, l++; else t[++m] = -1, r++; int p = 0, c = 0, d = 0, mn = n; for (int k = 1; k <= m; k++) { c += t[k]; if (t[k] == -1) { for (int k_ = p; k_ < k; k_++) mn = min(mn, d += t[k_]); p = k; } ans = max(ans, c - mn); } } printf("%d\n", ans); return 0; }

Compilation message (stderr)

roz.cpp: In function 'int main()':
roz.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
roz.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...