답안 #885120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
885120 2023-12-09T03:05:14 Z catlover Difference (POI11_roz) C++14
60 / 100
572 ms 36884 KB
#include <bits/stdc++.h>

#define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define SZ(X) (int)((X).size())

using namespace std;

const int maxN = 1e6;

int N;
string s;
vector<int> id[maxN+5];

void read_input()
{
  cin >> N >> s;
}

void solve()
{
  s = ' ' + s;
  FOR(i, 1, N) id[s[i] - 'a'].pb(i);

  int res = 0;
  FOR(x, 0, 25)
  {
    FOR(y, 0, 25)
    {
      if(SZ(id[x]) * SZ(id[y]) == 0) continue;
      if(x == y) continue;
      vector<int> d;
      int j = 0;
      for(int i : id[x])
      {
        while(j < SZ(id[y]) && id[y][j] < i)
        {
          ++j;
          d.pb(-1);
        }
        d.pb(1);
      }
      while(j < SZ(id[y]))
      {
        ++j;
        d.pb(-1);
      }
      int last = 0, mn = 1e9;
      vector<int> f(SZ(d), 0);
      FOR(i, 0, SZ(d) - 1)
      {
        f[i] = f[i - 1] + d[i];
        if(i > 1 && d[i] != d[i - 1])
        {
          FOR(j, last, i - 2) mn = min(mn, f[j]);
          last = i - 1;
        }
        res = max(res, f[i] - mn);
      }
    }
  }
  cout << res;
}

int main()
{
  cin.tie(0)->sync_with_stdio(0);

  file("SSDIFF");

  read_input();
  solve();

  return 0;
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:3:56: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:71:3: note: in expansion of macro 'file'
   71 |   file("SSDIFF");
      |   ^~~~
roz.cpp:3:89: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
      |                                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:71:3: note: in expansion of macro 'file'
   71 |   file("SSDIFF");
      |   ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Incorrect 5 ms 23900 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 23980 KB Output is correct
2 Correct 6 ms 23900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23900 KB Output is correct
2 Correct 6 ms 23896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 24604 KB Output is correct
2 Incorrect 5 ms 23896 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 571 ms 31912 KB Output is correct
2 Correct 6 ms 23900 KB Output is correct
3 Correct 279 ms 29940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 572 ms 31684 KB Output is correct
2 Correct 418 ms 30364 KB Output is correct
3 Correct 152 ms 30948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 562 ms 31524 KB Output is correct
2 Runtime error 67 ms 36736 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 560 ms 31520 KB Output is correct
2 Runtime error 39 ms 36884 KB Memory limit exceeded
3 Halted 0 ms 0 KB -