제출 #1132098

#제출 시각아이디문제언어결과실행 시간메모리
1132098lopkus스탬프 수집 (JOI16_ho_t2)C++20
50 / 100
2095 ms3644 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<char> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } int f = 0; vector<int> prefj(n + 1, 0); vector<int> sufi(n + 3, 0); for(int i = 1; i <= n; i++) { prefj[i] = prefj[i - 1] + (a[i] == 'J'); } for(int i = n; i >= 1; i--) { sufi[i] = sufi[i + 1] + (a[i] == 'I'); } for(int i = 1; i <= n; i++) { if(a[i] != 'J') { continue; } for(int j = i + 1; j <= n; j++) { if(a[j] == 'O') { f += sufi[j + 1]; } } } int ans = 0; vector<int> sufiksj(n + 2, 0); for(int i = n; i >= 1; i--) { sufiksj[i] = sufiksj[i + 1]; if(a[i] == 'O') { sufiksj[i] += sufi[i + 1]; } } vector<int> prefiksi(n + 1, 0); for(int i = 1; i <= n; i++) { prefiksi[i] = prefiksi[i - 1]; if(a[i] == 'O') { prefiksi[i] += prefj[i - 1]; } } for(int i = 1; i <= n; i++) { int ansj = f; int anso = f; int ansi = f; /* for(int j = i; j <= n; j++) { if(a[j] == 'O') { ansj += sufi[j + 1]; } }*/ ansj += sufiksj[i]; anso += prefj[i - 1] * sufi[i]; /* for(int j = i - 1; j >= 1; j--) { if(a[j] == 'O') { ansi += prefj[j - 1]; } }*/ ansi += prefiksi[i - 1]; ans = max({ans, ansj, ansi, anso}); } int ansn = f; for(int i = n; i >= 1; i--) { if(a[i] == 'O') { ansn += prefj[i - 1]; } } ans = max(ans, ansn); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...