Submission #1003045

#TimeUsernameProblemLanguageResultExecution timeMemory
1003045wibulordDifference (POI11_roz)C++17
100 / 100
684 ms18264 KiB
#include <bits/stdc++.h> #define endl '\n' #define ll long long #define fi first #define se second #define pb emplace_back #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define sz(s) (int)((s).size()) #define all(a) a.begin(), a.end() #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define F0R(i, b) for (int i = 0, _b = (b); i < _b; ++i) #define FORd(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) #define F0Rd(i, b) for (int i = (b)-1; i >= 0; i--) using namespace std; template<typename T1,typename T2> bool ckmax(T1 &x,const T2 &y){if(x<y){x=y; return 1;} return 0;} template<typename T1,typename T2> bool ckmin(T1 &x,const T2 &y){if(y<x){x=y; return 1;} return 0;} const int MOD = (int)1e9 + 7; const int mod = 998244353; const int N = 1e6 + 10, M = 18; const int INF = (int)2e9 + 11; /* /\_/\ (= ._.) / >? \>$ */ int n; char c[N]; int pref[N]; vector<int> ds[101]; vector<int> A; int calc(int a, int b){ if(sz(ds[a]) == 0 || sz(ds[b]) == 0) return 0; vector<int>().swap(A); A.push_back(0); int j = 0; F0R(i, sz(ds[a])){ for(; j < sz(ds[b]) && ds[b][j] < ds[a][i]; j++) A.push_back(-1); A.push_back(1); } for(; j < sz(ds[b]); j++) A.push_back(-1); int m = sz(A) - 1; FOR(i, 1, m) pref[i] = pref[i-1] + A[i]; int lst = -1, ptr = 0, ans = 0, mn = INF; FOR(i, 1, m){ if(A[i] < 0) lst = i; for(; ptr < lst; ptr++) mn = min(mn, pref[ptr]); if(lst != -1) ans = max(ans, pref[i] - mn); } return ans; } void sol(void){ cin >> n; FOR(i, 1, n){ cin >> c[i]; ds[c[i]-'a'].push_back(i); } int ans = 0; F0R(i, 26) F0R(j, 26) if(i != j) ans = max(ans, calc(i,j)); cout << ans << '\n'; } signed main(void){ #define TASK "nhap" if(fopen(TASK".inp", "r")){ freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin >> t; while(t--) sol(); cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n"; }

Compilation message (stderr)

roz.cpp: In function 'int main()':
roz.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...