제출 #153705

#제출 시각아이디문제언어결과실행 시간메모리
153705kimcodingSajam (COCI18_sajam)C++17
90 / 90
71 ms2424 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...