답안 #43200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43200 2018-03-10T14:34:28 Z baactree 즐거운 사진 수집 (JOI13_collecting) C++14
100 / 100
2090 ms 44456 KB
#include <bits/stdc++.h>
using namespace std;
int n, q;
int r[21], c[21];
int ro[1 << 20], co[1 << 20];
int rs[21][1 << 20], cs[21][1 << 20];
int main() {
	scanf("%d%d", &n, &q);
	long long cnt = 0;
	for (int i = 1; i <= n; i++) 
		r[i] = c[i] = 1 << (n - i);
	while (q--) {
		int a, b;
		scanf("%d%d", &a, &b);
		b--;
		if (a) {
			//col
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				int pre = cs[i][b / d];
				int now = co[b] ? pre - 1 : pre + 1;
				cs[i][b / d] = now;
				long long k = 0;
				if (!(pre%d))c[i]--, k = 1;
				if (!(now%d))c[i]++, k = -1;
				cnt += r[i] * k;
			}
			co[b] ^= 1;
		}
		else {
			//row
			for (int i = 1, d = 2; i <= n; i++, d <<= 1) {
				int pre = rs[i][b / d];
				int now = ro[b] ? pre - 1 : pre + 1;
				rs[i][b / d] = now;
				long long k = 0;
				if (!(pre%d))r[i]--, k = 1;
				if (!(now%d))r[i]++, k = -1;
				cnt += c[i] * k;
			}
			ro[b] ^= 1;
		}
		printf("%lld\n", cnt * 4 + 1);
	}
	return 0;
}

Compilation message

collecting.cpp: In function 'int main()':
collecting.cpp:8:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &q);
                       ^
collecting.cpp:14:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a, &b);
                        ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 664 KB Output is correct
4 Correct 2 ms 664 KB Output is correct
5 Correct 2 ms 664 KB Output is correct
6 Correct 1 ms 664 KB Output is correct
7 Correct 2 ms 664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 704 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 4 ms 764 KB Output is correct
4 Correct 3 ms 780 KB Output is correct
5 Correct 2 ms 780 KB Output is correct
6 Correct 3 ms 796 KB Output is correct
7 Correct 3 ms 796 KB Output is correct
8 Correct 3 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2054 ms 44156 KB Output is correct
2 Correct 1953 ms 44220 KB Output is correct
3 Correct 1714 ms 44220 KB Output is correct
4 Correct 1914 ms 44456 KB Output is correct
5 Correct 1895 ms 44456 KB Output is correct
6 Correct 1939 ms 44456 KB Output is correct
7 Correct 1994 ms 44456 KB Output is correct
8 Correct 1921 ms 44456 KB Output is correct
9 Correct 1629 ms 44456 KB Output is correct
10 Correct 1850 ms 44456 KB Output is correct
11 Correct 2090 ms 44456 KB Output is correct
12 Correct 1924 ms 44456 KB Output is correct
13 Correct 1781 ms 44456 KB Output is correct