Submission #885124

# Submission time Handle Problem Language Result Execution time Memory
885124 2023-12-09T03:10:09 Z catlover Difference (POI11_roz) C++14
80 / 100
592 ms 36872 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(id[x].empty() || id[y].empty()) continue;
      if(x == y) continue;
      vector<int> d {0};
      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 cur = 0, last = 0, mn = 1e9;
      vector<int> f(SZ(d), 0);
      FOR(i, 1, 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;
        }
        cur = max(cur, f[i] - mn);
      }
      res = max(res, cur);
    }
  }
  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:72:3: note: in expansion of macro 'file'
   72 |   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:72:3: note: in expansion of macro 'file'
   72 |   file("SSDIFF");
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
4 Correct 5 ms 23940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 6 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 23896 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 5 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 23900 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 23900 KB Output is correct
2 Correct 7 ms 23900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 24408 KB Output is correct
2 Correct 5 ms 23900 KB Output is correct
3 Correct 9 ms 24080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 588 ms 31916 KB Output is correct
2 Correct 5 ms 23896 KB Output is correct
3 Correct 296 ms 29856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 592 ms 31680 KB Output is correct
2 Correct 436 ms 30180 KB Output is correct
3 Correct 160 ms 31156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 587 ms 31524 KB Output is correct
2 Runtime error 71 ms 36700 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 589 ms 31572 KB Output is correct
2 Runtime error 41 ms 36872 KB Memory limit exceeded
3 Halted 0 ms 0 KB -