답안 #153705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153705 2019-09-15T09:16:27 Z kimcoding Sajam (COCI18_sajam) C++17
90 / 90
71 ms 2424 KB
#include <cstdio>
#include <algorithm>
using namespace std;

bool chk[2][1005], map[1005][1005];
int cnt[2][1005], n, k, sum;

bool solve(int t) {
	if (sum <= k) return true;
	for (t = 1; t <= n * 2; t++) {
		int Max = -1, a, b;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j <= 1; j++) {
				if (chk[j][i]) continue;
				if (Max < cnt[j][i])
					Max = cnt[j][i], a = j, b = i;
			}
		}
		chk[a][b] = true;
		sum += n - 2 * cnt[a][b];
		cnt[a][b] = n - cnt[a][b];
		for (int i = 1; i <= n; i++)
			cnt[!a][i] += ((map[a ? b : i][a ? i : b] ^= 1) ? 1 : -1);
		if (sum <= k) return true;
	}
	return false;
}

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			char x;
			scanf(" %c", &x);
			map[i][j] = (x == 'o');
			cnt[0][j] += map[i][j];
			cnt[1][i] += map[i][j];
		}
		sum += cnt[1][i];
	}
	printf("%s\n", solve(0) ? "DA" : "NE");
	return 0;
}

Compilation message

sajam.cpp: In function 'int main()':
sajam.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~
sajam.cpp:34:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &x);
    ~~~~~^~~~~~~~~~~
sajam.cpp: In function 'bool solve(int)':
sajam.cpp:20:26: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   sum += n - 2 * cnt[a][b];
                  ~~~~~~~~^
sajam.cpp:20:26: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 13 ms 864 KB Output is correct
3 Correct 20 ms 1144 KB Output is correct
4 Correct 52 ms 2040 KB Output is correct
5 Correct 54 ms 1020 KB Output is correct
6 Correct 9 ms 760 KB Output is correct
7 Correct 20 ms 1016 KB Output is correct
8 Correct 64 ms 2040 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 65 ms 2040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1680 KB Output is correct
2 Correct 44 ms 1756 KB Output is correct
3 Correct 30 ms 1416 KB Output is correct
4 Correct 26 ms 1400 KB Output is correct
5 Correct 50 ms 1912 KB Output is correct
6 Correct 21 ms 1148 KB Output is correct
7 Correct 38 ms 1528 KB Output is correct
8 Correct 42 ms 1656 KB Output is correct
9 Correct 13 ms 888 KB Output is correct
10 Correct 71 ms 2280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 1904 KB Output is correct
2 Correct 47 ms 1920 KB Output is correct
3 Correct 27 ms 1400 KB Output is correct
4 Correct 34 ms 1528 KB Output is correct
5 Correct 36 ms 1656 KB Output is correct
6 Correct 64 ms 2232 KB Output is correct
7 Correct 17 ms 1016 KB Output is correct
8 Correct 36 ms 1528 KB Output is correct
9 Correct 42 ms 1696 KB Output is correct
10 Correct 70 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 1400 KB Output is correct
2 Correct 28 ms 1348 KB Output is correct
3 Correct 59 ms 2168 KB Output is correct
4 Correct 20 ms 1144 KB Output is correct
5 Correct 30 ms 1400 KB Output is correct
6 Correct 65 ms 2168 KB Output is correct
7 Correct 21 ms 1144 KB Output is correct
8 Correct 24 ms 1144 KB Output is correct
9 Correct 25 ms 1188 KB Output is correct
10 Correct 24 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 2424 KB Output is correct
2 Correct 59 ms 2248 KB Output is correct
3 Correct 54 ms 2040 KB Output is correct
4 Correct 34 ms 1528 KB Output is correct
5 Correct 36 ms 1528 KB Output is correct
6 Correct 40 ms 1656 KB Output is correct
7 Correct 23 ms 1172 KB Output is correct
8 Correct 57 ms 1964 KB Output is correct
9 Correct 32 ms 1400 KB Output is correct
10 Correct 65 ms 2156 KB Output is correct