Submission #937596

# Submission time Handle Problem Language Result Execution time Memory
937596 2024-03-04T09:31:12 Z WonderfulWhale Lamps (JOI19_lamps) C++17
0 / 100
41 ms 58272 KB
#include<bits/stdc++.h>
using namespace std;

#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

const int CNST = 364;
const int CNST2 = 5;

int dp[10009][CNST];

int dis[CNST][CNST2] = {
	{-1, -1, -1, -1, -1},
	{0, -1, -1, -1, -1},
	{0, 0, -1, -1, -1},
	{0, 0, 0, -1, -1},
	{0, 0, 0, 0, -1},
	{0, 0, 0, 0, 0},
	{0, 0, 0, 0, 1},
	{0, 0, 0, 0, 2},
	{0, 0, 0, 1, -1},
	{0, 0, 0, 1, 0},
	{0, 0, 0, 1, 1},
	{0, 0, 0, 1, 2},
	{0, 0, 0, 2, -1},
	{0, 0, 0, 2, 0},
	{0, 0, 0, 2, 1},
	{0, 0, 0, 2, 2},
	{0, 0, 1, -1, -1},
	{0, 0, 1, 0, -1},
	{0, 0, 1, 0, 0},
	{0, 0, 1, 0, 1},
	{0, 0, 1, 0, 2},
	{0, 0, 1, 1, -1},
	{0, 0, 1, 1, 0},
	{0, 0, 1, 1, 1},
	{0, 0, 1, 1, 2},
	{0, 0, 1, 2, -1},
	{0, 0, 1, 2, 0},
	{0, 0, 1, 2, 1},
	{0, 0, 1, 2, 2},
	{0, 0, 2, -1, -1},
	{0, 0, 2, 0, -1},
	{0, 0, 2, 0, 0},
	{0, 0, 2, 0, 1},
	{0, 0, 2, 0, 2},
	{0, 0, 2, 1, -1},
	{0, 0, 2, 1, 0},
	{0, 0, 2, 1, 1},
	{0, 0, 2, 1, 2},
	{0, 0, 2, 2, -1},
	{0, 0, 2, 2, 0},
	{0, 0, 2, 2, 1},
	{0, 0, 2, 2, 2},
	{0, 1, -1, -1, -1},
	{0, 1, 0, -1, -1},
	{0, 1, 0, 0, -1},
	{0, 1, 0, 0, 0},
	{0, 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1, 2, -1},
	{2, 2, 1, 2, 0},
	{2, 2, 1, 2, 1},
	{2, 2, 1, 2, 2},
	{2, 2, 2, -1, -1},
	{2, 2, 2, 0, -1},
	{2, 2, 2, 0, 0},
	{2, 2, 2, 0, 1},
	{2, 2, 2, 0, 2},
	{2, 2, 2, 1, -1},
	{2, 2, 2, 1, 0},
	{2, 2, 2, 1, 1},
	{2, 2, 2, 1, 2},
	{2, 2, 2, 2, -1},
	{2, 2, 2, 2, 0},
	{2, 2, 2, 2, 1},
	{2, 2, 2, 2, 2,},

};

int f(int a, int b) {
	for(int i=0;i<4;i++) {
		if(dis[a][i]!=dis[b][i]) {
			for(int j=0;j<5;j++) {
				if(j==4||dis[b][j]==-1)
					return j-i;
			}
		}
	}
	return 0;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);


	int n;
	cin >> n;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<CNST;j++) {
			dp[i][j] = 1e9;
		}
	}
	dp[0][0] = 0;
	string A, B;
	cin >> A >> B;
	//for(int i=0;i<CNST;i++) {
		//for(int j=0;j<CNST;j++) {
			//cout << f(i, j) << " ";
		//}
		//cout << "\n";
	//}
	for(int i=1;i<=n;i++) {
		for(int j=0;j<CNST;j++) {
			for(int k=0;k<CNST;k++) {
				int New = A[i-1]-'0';
				for(int I=0;I<4;I++) {
					if(dis[k][I]==0) New = 0;
					if(dis[k][I]==1) New = 1;
					if(dis[k][I]==2) New = 1-New;
				}
				if(New!=B[i-1]-'0') continue;
				dp[i][k] = min(dp[i][k], dp[i-1][j]+f(j, k));
			}
		}
		//for(int j=0;j<CNST;j++) {
			//cout << i << " " << j << ": " << dp[i][j] << "\n";
		//}
	}
	int ans = 1e9;
	for(int i=0;i<=n;i++) {
		for(int j=0;j<CNST;j++) {
			ans = min(ans, dp[n][j]);
		}
	}
	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 4 ms 472 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 33 ms 500 KB Output is correct
9 Correct 27 ms 348 KB Output is correct
10 Correct 25 ms 348 KB Output is correct
11 Correct 25 ms 352 KB Output is correct
12 Correct 27 ms 352 KB Output is correct
13 Correct 25 ms 352 KB Output is correct
14 Correct 26 ms 352 KB Output is correct
15 Correct 30 ms 352 KB Output is correct
16 Correct 27 ms 352 KB Output is correct
17 Correct 25 ms 348 KB Output is correct
18 Correct 27 ms 528 KB Output is correct
19 Correct 26 ms 600 KB Output is correct
20 Correct 26 ms 348 KB Output is correct
21 Correct 36 ms 348 KB Output is correct
22 Correct 37 ms 344 KB Output is correct
23 Correct 27 ms 344 KB Output is correct
24 Correct 26 ms 344 KB Output is correct
25 Correct 34 ms 344 KB Output is correct
26 Incorrect 27 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 4 ms 472 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 33 ms 500 KB Output is correct
9 Correct 27 ms 348 KB Output is correct
10 Correct 25 ms 348 KB Output is correct
11 Correct 25 ms 352 KB Output is correct
12 Correct 27 ms 352 KB Output is correct
13 Correct 25 ms 352 KB Output is correct
14 Correct 26 ms 352 KB Output is correct
15 Correct 30 ms 352 KB Output is correct
16 Correct 27 ms 352 KB Output is correct
17 Correct 25 ms 348 KB Output is correct
18 Correct 27 ms 528 KB Output is correct
19 Correct 26 ms 600 KB Output is correct
20 Correct 26 ms 348 KB Output is correct
21 Correct 36 ms 348 KB Output is correct
22 Correct 37 ms 344 KB Output is correct
23 Correct 27 ms 344 KB Output is correct
24 Correct 26 ms 344 KB Output is correct
25 Correct 34 ms 344 KB Output is correct
26 Incorrect 27 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 5 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Runtime error 41 ms 58272 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 4 ms 472 KB Output is correct
5 Correct 4 ms 604 KB Output is correct
6 Correct 3 ms 348 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 33 ms 500 KB Output is correct
9 Correct 27 ms 348 KB Output is correct
10 Correct 25 ms 348 KB Output is correct
11 Correct 25 ms 352 KB Output is correct
12 Correct 27 ms 352 KB Output is correct
13 Correct 25 ms 352 KB Output is correct
14 Correct 26 ms 352 KB Output is correct
15 Correct 30 ms 352 KB Output is correct
16 Correct 27 ms 352 KB Output is correct
17 Correct 25 ms 348 KB Output is correct
18 Correct 27 ms 528 KB Output is correct
19 Correct 26 ms 600 KB Output is correct
20 Correct 26 ms 348 KB Output is correct
21 Correct 36 ms 348 KB Output is correct
22 Correct 37 ms 344 KB Output is correct
23 Correct 27 ms 344 KB Output is correct
24 Correct 26 ms 344 KB Output is correct
25 Correct 34 ms 344 KB Output is correct
26 Incorrect 27 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -