# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
831477 |
2023-08-20T09:36:04 Z |
OrazB |
Miners (IOI07_miners) |
C++14 |
|
1500 ms |
1728 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define ll long long int
#define pii pair <int, int>
#define pb push_back
#define ff first
#define ss second
const int N = 1e5+5;
int nw[26], A[3], vis[N];
pair<int,pii> dp[N][5];
int T(char c){
if (c == 'M') return 0;
if (c == 'B') return 1;
return 2;
}
int main ()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
string s;
cin >> n >> s;
int mx = 0, x = 0, y = 0;
for (int i = 1; i < n; i++){
for (int j = i-1; j >= 0; j--){
int p = T(s[j]);
for (int k = 0; k < 3; k++){
if (dp[j][k].ff == 0) continue;
A[k] = 1;
A[T(s[i])] = 1;
A[p] = 1;
int cnt = (A[0]+A[1]+A[2]);
if (dp[i][p].ff < cnt+dp[j][k].ff){
dp[i][p] = {cnt+dp[j][k].ff, {j, k}};
}
A[0] = A[1] = A[2] = 0;
}
if (dp[i][p].ff < (s[i]!=s[j])+2){
dp[i][p] = {(s[i]!=s[j])+2, {j, -1e9}};
}
if (mx <= dp[i][p].ff){
mx = dp[i][p].ff;
x = i;
y = p;
}
}
}
int ans = 0;
ans += mx;
while(1){
vis[x] = 1;
if (x == 0) break;
int new_x, new_y;
new_x = dp[x][y].ss.ff;
new_y = dp[x][y].ss.ss;
x = new_x;
y = new_y;
}
string str = "";
for (int i = 0; i < n; i++) if (vis[i] == 0) str += s[i];
for (int i = 0; i < str.size(); i++){
for (int j = i; j > max(i-3, -1); j--){
A[T(str[j])] = 1;
}
ans += A[0]+A[1]+A[2];
A[0] = A[1] = A[2] = 0;
}
cout << ans << '\n';
}
Compilation message
miners.cpp: In function 'int main()':
miners.cpp:70:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for (int i = 0; i < str.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
138 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
487 ms |
916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1551 ms |
1192 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1575 ms |
1444 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1566 ms |
1728 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |