# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
632004 |
2022-08-19T09:48:04 Z |
radal |
Lamps (JOI19_lamps) |
C++17 |
|
9 ms |
5364 KB |
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define pb push_back
#define X first
#define Y second
#define debug(x) cerr << #x << " : " << x << endl;
#define all(x) x.begin() , x.end()
using namespace std;
typedef pair<int,int> pll;
typedef long long ll;
constexpr int N = 2e3+10;
int cal[N][5],a[N][3],dp[N],pd[N][N][3];
int main(){
ios_base :: sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
string s,t;
cin >> s >> t;
s = '#'+s;
t = '#'+t;
cal[0][0] = 1;
cal[0][1] = 1;
cal[0][2] = 1;
rep(i,1,n+1){
rep(j,0,5){
if (j == 3) continue;
if (j == 4){
if (s[i] == t[i]){
cal[i][j] = cal[i-1][3];
continue;
}
cal[i][j] = min(cal[i-1][2],cal[i-1][t[i]-'0']);
continue;
}
if (j == 2){
if (s[i] == t[i]){
cal[i][j] = min({cal[i-1][s[i]-'0']+1,cal[i-1][j]+1,2+cal[i-1][3]});
continue;
}
cal[i][j] = min(cal[i-1][j],cal[i-1][3]+1);
continue;
}
else{
if (j+'0' == t[i]){
cal[i][j] = min(cal[i-1][j],cal[i-1][3]+1);
continue;
}
cal[i][j] = min(cal[i-1][j]+1,cal[i-1][3]+2);
continue;
}
}
cal[i][3] = min({cal[i][0],cal[i][1],cal[i][2],cal[i][4]});
}
rep(i,1,n+1){
if (t[i] == '1') a[i][1] = 1+a[i-1][1];
else a[i][0] = 1+a[i-1][0];
}
repr(l,n,1){
rep(r,l,n+1){
if (t[r] == '1'){
pd[l][r][1] = pd[l][r-1][1];
if (a[r][1] >= r-l+1){
pd[l][r][0] = 1;
continue;
}
pd[l][r][0] = pd[l][r-a[r][1]][0]+1;
}
else{
pd[l][r][0] = pd[l][r-1][0];
if (a[r][0] >= r-l+1){
pd[l][r][1] = 1;
continue;
}
pd[l][r][1] = pd[l][r-a[r][0]][1]+1;
}
}
}
rep(i,1,n+1){
if (s[i] == t[i]){
dp[i] = dp[i-1];
continue;
}
dp[i] = 1+dp[i-1];
bool fl = 1;
repr(j,i-1,1){
fl &= (s[j] != t[j]);
dp[i] = min(dp[i],dp[j-1]+min(pd[j][i][0],pd[j][i][1])+1);
if (fl) dp[i] = min(dp[i],dp[j-1]+1);
}
}
cout << min(dp[n],cal[n][3]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
328 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Runtime error |
9 ms |
5364 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |