Submission #696331

# Submission time Handle Problem Language Result Execution time Memory
696331 2023-02-06T09:01:38 Z dongliu0426 Difference (POI11_roz) C++17
50 / 100
1000 ms 2560 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
using namespace std;

const int N = 1e6;

int main() {
  int n;
  scanf("%d", &n);
  static char s[N];
  scanf("%s", s);
  int ans = 0;
  for (int i = 0; i < 26; i++)
    for (int j = 0; j < 26; j++) {
      static int t[N + 1];
      int m = 0;
      for (int k = 0; k < n; k++)
        if (s[k] == 'a' + i)
          t[++m] = +1;
        else if (s[k] == 'a' + j)
          t[++m] = -1;
      int p = 0, c = 0, d = 0, mn = n;
      for (int k = 1; k <= m; k++) {
        c += t[k];
        ans = max(ans, c - mn);
        if (t[k] == -1) {
          for (int k_ = p; k_ < k; k_++)
            mn = min(mn, d += t[k_]);
          p = k;
        }
      }
    }
  printf("%d\n", ans);
  return 0;
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
roz.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 528 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 14 ms 356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 2496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 2556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 2560 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 2516 KB Time limit exceeded
2 Halted 0 ms 0 KB -