Submission #330651

# Submission time Handle Problem Language Result Execution time Memory
330651 2020-11-26T04:44:25 Z limabeans Lamps (JOI19_lamps) C++17
6 / 100
451 ms 6632 KB
#include <bits/stdc++.h>
using namespace std;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e6 + 5;


int n;
int dp[1<<19];


int convert(string a) {
        int tmp = 0;
    for (char c: a) {
	tmp *= 2;
	tmp += (c-'0');
    }
    return tmp;
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);

    cin>>n;
    string a, b;
    cin>>a;
    cin>>b;

    int start = convert(a);

    for (int i=0; i<1<<n; i++) {
	dp[i] = 1e9;
    }

    
    dp[start] = 0;
    queue<int> qq;
    qq.push(start);


    auto flip = [&](int mask, int l, int r) {
	int cover = (1<<(r-l+1)) - 1;
	cover <<= l;
	return mask^cover;
    };

    auto one = [&](int mask, int l, int r) {
	int cover = (1<<(r-l+1)) - 1;
	cover <<= l;
	return mask|cover;
    };


    auto zero = [&](int mask, int l, int r) {
	int cover = (1<<(r-l+1)) - 1;
	cover <<= l;
	return mask&(~cover);
    };

    while (qq.size()) {
	int mask = qq.front();
	qq.pop();

	for (int l=0; l<n; l++) {
	    for (int r=l; r<n; r++) {
		for (int nmask: {flip(mask,l,r), one(mask,l,r), zero(mask,l,r)}) {
		    if (dp[nmask]>1+dp[mask]) {
			dp[nmask] = 1+dp[mask];
			qq.push(nmask);
		    }
		}
	    }
	}
    }


    cout<<dp[convert(b)]<<endl;
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 389 ms 2028 KB Output is correct
9 Correct 437 ms 1900 KB Output is correct
10 Correct 160 ms 1156 KB Output is correct
11 Correct 158 ms 1132 KB Output is correct
12 Correct 449 ms 1936 KB Output is correct
13 Correct 158 ms 1388 KB Output is correct
14 Correct 422 ms 1888 KB Output is correct
15 Correct 156 ms 1260 KB Output is correct
16 Correct 393 ms 1900 KB Output is correct
17 Correct 175 ms 1400 KB Output is correct
18 Correct 404 ms 1848 KB Output is correct
19 Correct 177 ms 1132 KB Output is correct
20 Correct 370 ms 1900 KB Output is correct
21 Correct 184 ms 1260 KB Output is correct
22 Correct 397 ms 2048 KB Output is correct
23 Correct 186 ms 1132 KB Output is correct
24 Correct 425 ms 2164 KB Output is correct
25 Correct 158 ms 1260 KB Output is correct
26 Correct 451 ms 2028 KB Output is correct
27 Correct 163 ms 1156 KB Output is correct
28 Correct 78 ms 748 KB Output is correct
29 Correct 402 ms 1900 KB Output is correct
30 Correct 155 ms 1132 KB Output is correct
31 Correct 81 ms 768 KB Output is correct
32 Correct 396 ms 1900 KB Output is correct
33 Correct 165 ms 1168 KB Output is correct
34 Correct 74 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 389 ms 2028 KB Output is correct
9 Correct 437 ms 1900 KB Output is correct
10 Correct 160 ms 1156 KB Output is correct
11 Correct 158 ms 1132 KB Output is correct
12 Correct 449 ms 1936 KB Output is correct
13 Correct 158 ms 1388 KB Output is correct
14 Correct 422 ms 1888 KB Output is correct
15 Correct 156 ms 1260 KB Output is correct
16 Correct 393 ms 1900 KB Output is correct
17 Correct 175 ms 1400 KB Output is correct
18 Correct 404 ms 1848 KB Output is correct
19 Correct 177 ms 1132 KB Output is correct
20 Correct 370 ms 1900 KB Output is correct
21 Correct 184 ms 1260 KB Output is correct
22 Correct 397 ms 2048 KB Output is correct
23 Correct 186 ms 1132 KB Output is correct
24 Correct 425 ms 2164 KB Output is correct
25 Correct 158 ms 1260 KB Output is correct
26 Correct 451 ms 2028 KB Output is correct
27 Correct 163 ms 1156 KB Output is correct
28 Correct 78 ms 748 KB Output is correct
29 Correct 402 ms 1900 KB Output is correct
30 Correct 155 ms 1132 KB Output is correct
31 Correct 81 ms 768 KB Output is correct
32 Correct 396 ms 1900 KB Output is correct
33 Correct 165 ms 1168 KB Output is correct
34 Correct 74 ms 748 KB Output is correct
35 Runtime error 3 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Runtime error 10 ms 6632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 389 ms 2028 KB Output is correct
9 Correct 437 ms 1900 KB Output is correct
10 Correct 160 ms 1156 KB Output is correct
11 Correct 158 ms 1132 KB Output is correct
12 Correct 449 ms 1936 KB Output is correct
13 Correct 158 ms 1388 KB Output is correct
14 Correct 422 ms 1888 KB Output is correct
15 Correct 156 ms 1260 KB Output is correct
16 Correct 393 ms 1900 KB Output is correct
17 Correct 175 ms 1400 KB Output is correct
18 Correct 404 ms 1848 KB Output is correct
19 Correct 177 ms 1132 KB Output is correct
20 Correct 370 ms 1900 KB Output is correct
21 Correct 184 ms 1260 KB Output is correct
22 Correct 397 ms 2048 KB Output is correct
23 Correct 186 ms 1132 KB Output is correct
24 Correct 425 ms 2164 KB Output is correct
25 Correct 158 ms 1260 KB Output is correct
26 Correct 451 ms 2028 KB Output is correct
27 Correct 163 ms 1156 KB Output is correct
28 Correct 78 ms 748 KB Output is correct
29 Correct 402 ms 1900 KB Output is correct
30 Correct 155 ms 1132 KB Output is correct
31 Correct 81 ms 768 KB Output is correct
32 Correct 396 ms 1900 KB Output is correct
33 Correct 165 ms 1168 KB Output is correct
34 Correct 74 ms 748 KB Output is correct
35 Runtime error 3 ms 1280 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -