답안 #260389

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260389 2020-08-10T08:12:38 Z patrikpavic2 Lamps (JOI19_lamps) C++17
6 / 100
262 ms 8440 KB
#include <cstdio>
#include <cstring>
#include <queue>

using namespace std;

const int N = 1e6 + 500;

int dis[N], n, A, B;
queue < int > Q;

int main(){
	memset(dis, -1, sizeof(dis));
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		char c; scanf(" %c", &c);
		A += (1 << i) * (c - '0');
	}
	for(int i = 0;i < n;i++){
		char c; scanf(" %c", &c);
		B += (1 << i) * (c - '0');
	}
	dis[A] = 0; Q.push(A);
	for(;!Q.empty();Q.pop()){
		int cur = Q.front();
		for(int l = 0;l < n;l++){
			int t1 = cur, t2 = cur, t3 = cur;
			for(int r = l;r < n;r++){
				t1 &= (1 << n) - (1 << r) - 1;
				t2 |= (1 << r);
				t3 ^= (1 << r);
				if(dis[t1] == -1){
					dis[t1] = dis[cur] + 1;
					Q.push(t1);
				}
				if(dis[t2] == -1){
					dis[t2] = dis[cur] + 1;
					Q.push(t2);
				}
				if(dis[t3] == -1){
					dis[t3] = dis[cur] + 1;
					Q.push(t3);
				}
			}
		}
	}
	printf("%d\n", dis[B]);
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lamp.cpp:16:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char c; scanf(" %c", &c);
           ~~~~~^~~~~~~~~~~
lamp.cpp:20:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   char c; scanf(" %c", &c);
           ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 2 ms 4224 KB Output is correct
3 Correct 3 ms 4224 KB Output is correct
4 Correct 3 ms 4224 KB Output is correct
5 Correct 3 ms 4224 KB Output is correct
6 Correct 2 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 253 ms 4728 KB Output is correct
9 Correct 256 ms 4600 KB Output is correct
10 Correct 102 ms 4480 KB Output is correct
11 Correct 109 ms 4472 KB Output is correct
12 Correct 252 ms 4856 KB Output is correct
13 Correct 101 ms 4480 KB Output is correct
14 Correct 253 ms 4728 KB Output is correct
15 Correct 103 ms 4600 KB Output is correct
16 Correct 248 ms 4736 KB Output is correct
17 Correct 101 ms 4480 KB Output is correct
18 Correct 250 ms 4856 KB Output is correct
19 Correct 105 ms 4480 KB Output is correct
20 Correct 253 ms 4728 KB Output is correct
21 Correct 108 ms 4540 KB Output is correct
22 Correct 255 ms 4728 KB Output is correct
23 Correct 105 ms 4480 KB Output is correct
24 Correct 251 ms 4856 KB Output is correct
25 Correct 121 ms 4480 KB Output is correct
26 Correct 249 ms 4728 KB Output is correct
27 Correct 103 ms 4480 KB Output is correct
28 Correct 44 ms 4352 KB Output is correct
29 Correct 249 ms 4736 KB Output is correct
30 Correct 103 ms 4480 KB Output is correct
31 Correct 46 ms 4352 KB Output is correct
32 Correct 262 ms 4828 KB Output is correct
33 Correct 115 ms 4480 KB Output is correct
34 Correct 45 ms 4352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 2 ms 4224 KB Output is correct
3 Correct 3 ms 4224 KB Output is correct
4 Correct 3 ms 4224 KB Output is correct
5 Correct 3 ms 4224 KB Output is correct
6 Correct 2 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 253 ms 4728 KB Output is correct
9 Correct 256 ms 4600 KB Output is correct
10 Correct 102 ms 4480 KB Output is correct
11 Correct 109 ms 4472 KB Output is correct
12 Correct 252 ms 4856 KB Output is correct
13 Correct 101 ms 4480 KB Output is correct
14 Correct 253 ms 4728 KB Output is correct
15 Correct 103 ms 4600 KB Output is correct
16 Correct 248 ms 4736 KB Output is correct
17 Correct 101 ms 4480 KB Output is correct
18 Correct 250 ms 4856 KB Output is correct
19 Correct 105 ms 4480 KB Output is correct
20 Correct 253 ms 4728 KB Output is correct
21 Correct 108 ms 4540 KB Output is correct
22 Correct 255 ms 4728 KB Output is correct
23 Correct 105 ms 4480 KB Output is correct
24 Correct 251 ms 4856 KB Output is correct
25 Correct 121 ms 4480 KB Output is correct
26 Correct 249 ms 4728 KB Output is correct
27 Correct 103 ms 4480 KB Output is correct
28 Correct 44 ms 4352 KB Output is correct
29 Correct 249 ms 4736 KB Output is correct
30 Correct 103 ms 4480 KB Output is correct
31 Correct 46 ms 4352 KB Output is correct
32 Correct 262 ms 4828 KB Output is correct
33 Correct 115 ms 4480 KB Output is correct
34 Correct 45 ms 4352 KB Output is correct
35 Runtime error 10 ms 8320 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 3 ms 4224 KB Output is correct
3 Correct 3 ms 4224 KB Output is correct
4 Correct 3 ms 4224 KB Output is correct
5 Correct 3 ms 4224 KB Output is correct
6 Correct 2 ms 4224 KB Output is correct
7 Runtime error 130 ms 8440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4224 KB Output is correct
2 Correct 2 ms 4224 KB Output is correct
3 Correct 3 ms 4224 KB Output is correct
4 Correct 3 ms 4224 KB Output is correct
5 Correct 3 ms 4224 KB Output is correct
6 Correct 2 ms 4224 KB Output is correct
7 Correct 3 ms 4224 KB Output is correct
8 Correct 253 ms 4728 KB Output is correct
9 Correct 256 ms 4600 KB Output is correct
10 Correct 102 ms 4480 KB Output is correct
11 Correct 109 ms 4472 KB Output is correct
12 Correct 252 ms 4856 KB Output is correct
13 Correct 101 ms 4480 KB Output is correct
14 Correct 253 ms 4728 KB Output is correct
15 Correct 103 ms 4600 KB Output is correct
16 Correct 248 ms 4736 KB Output is correct
17 Correct 101 ms 4480 KB Output is correct
18 Correct 250 ms 4856 KB Output is correct
19 Correct 105 ms 4480 KB Output is correct
20 Correct 253 ms 4728 KB Output is correct
21 Correct 108 ms 4540 KB Output is correct
22 Correct 255 ms 4728 KB Output is correct
23 Correct 105 ms 4480 KB Output is correct
24 Correct 251 ms 4856 KB Output is correct
25 Correct 121 ms 4480 KB Output is correct
26 Correct 249 ms 4728 KB Output is correct
27 Correct 103 ms 4480 KB Output is correct
28 Correct 44 ms 4352 KB Output is correct
29 Correct 249 ms 4736 KB Output is correct
30 Correct 103 ms 4480 KB Output is correct
31 Correct 46 ms 4352 KB Output is correct
32 Correct 262 ms 4828 KB Output is correct
33 Correct 115 ms 4480 KB Output is correct
34 Correct 45 ms 4352 KB Output is correct
35 Runtime error 10 ms 8320 KB Execution killed with signal 11 (could be triggered by violating memory limits)
36 Halted 0 ms 0 KB -