답안 #696337

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
696337 2023-02-06T09:12:34 Z dongliu0426 Difference (POI11_roz) C++17
100 / 100
599 ms 32688 KB
#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

roz.cpp: In function 'int main()':
roz.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
roz.cpp:11:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23764 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
4 Correct 12 ms 23684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23800 KB Output is correct
2 Correct 12 ms 23764 KB Output is correct
3 Correct 12 ms 23796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 23692 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 12 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23804 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23880 KB Output is correct
2 Correct 12 ms 23708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 24404 KB Output is correct
2 Correct 13 ms 23764 KB Output is correct
3 Correct 16 ms 24024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 30280 KB Output is correct
2 Correct 11 ms 23764 KB Output is correct
3 Correct 351 ms 28528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 598 ms 30120 KB Output is correct
2 Correct 463 ms 28536 KB Output is correct
3 Correct 148 ms 28692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 594 ms 30080 KB Output is correct
2 Correct 187 ms 31464 KB Output is correct
3 Correct 160 ms 29740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 599 ms 29828 KB Output is correct
2 Correct 171 ms 32688 KB Output is correct
3 Correct 167 ms 30440 KB Output is correct