Submission #885126

# Submission time Handle Problem Language Result Execution time Memory
885126 2023-12-09T03:10:57 Z catlover Difference (POI11_roz) C++14
100 / 100
588 ms 13528 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[31];

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 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;
        }
        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");
      |   ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 1108 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 5 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 588 ms 8420 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 286 ms 6496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 585 ms 8204 KB Output is correct
2 Correct 435 ms 7124 KB Output is correct
3 Correct 148 ms 7256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 584 ms 8228 KB Output is correct
2 Correct 68 ms 13528 KB Output is correct
3 Correct 115 ms 8224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 588 ms 8080 KB Output is correct
2 Correct 34 ms 13212 KB Output is correct
3 Correct 187 ms 8012 KB Output is correct