Submission #927743

#TimeUsernameProblemLanguageResultExecution timeMemory
927743weakweakweakJJOOII 2 (JOI20_ho_t2)C++14
13 / 100
7 ms3816 KiB
/* 5:05開始,也不算是virtual,因為我已經知道幾個人的分數了,也在去年資芽時聽過p4的題敘並想過。 所以就只是計時練習,應該會寫到19:05,然後等家長買晚餐回來吃後再把剩下的兩小時用一用,衝到div2就打div2 目標日本選訓!! */ //喔,就只是雙指針而已 #include <bits/stdc++.h> using namespace std; string s; int n, k, a[310000] = {0}; int wow[210000][3]; int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; cin >> s; for (int i = 1; i <= n; i++) { if (s[i-1] == 'J') a[i] = 0; if (s[i-1] == 'O') a[i] = 1; if (s[i-1] == 'I') a[i] = 2; } for (int z = 0; z < 3; z++) { for (int i = 1, j = 0, cnt = 0; i <= n; i++) { while (j + 1 <= n and cnt < k) { j++; if (a[j] == z) cnt++; } if (cnt == k) wow[i][z] = j + 1; else wow[i][z] = 209999; if (a[i] == z) cnt--; } } for (int i = n + 1; i <= 209999; i++)wow[i][0] = wow[i][1] = 209999, wow[i][2] = n * 114 + 514000; int ans = INT_MAX; for (int i = 1; i <= n; i++) { // cout << i << ' ' << wow[i][0] << ' ' << wow[i][1] << ' ' << wow[i][2] << '\n'; // cout << i << ' ' << wow[wow[wow[i][0]][1]][2] << '\n'; ans = min(ans, wow[wow[wow[i][0]][1]][2] - i - k * 3 ); } if (ans > n) ans = -1; cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...