Submission #167948

# Submission time Handle Problem Language Result Execution time Memory
167948 2019-12-11T01:59:13 Z YottaByte Red-blue table (IZhO19_stones) C++14
17 / 100
513 ms 376 KB
#include <iostream>

using namespace std;

#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;

const int mod = 1e9 + 7;										/// ANOTHER HASH MOD: 228228227
const int prime = 29;											/// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);

int n, m;

inline void purify() {
}

inline void precalc() {
}

inline void read() {
	scanf("%d %d", &n, &m);
}

inline int check(int mask) {
	int res = 0;
	for (int i = 0; i < n; i++) {
		int cnta = 0;
		for (int j = 0; j < m; j++) {
			if (mask >> (j + i * m) & 1) {
				cnta++;
			}
		}

		if (cnta > m / 2) {
			res++;
		}
	}

	for (int i = 0; i < m; i++) {
		int cntb = 0;
		for (int j = 0; i + j < m * n; j += m) {
			if (!(mask >> (j + i) & 1)) {
				cntb++;
			}
		}

		if (cntb > n / 2) {
			res++;
		}
	}

	return res;
}

void out(int mask) {
  	if (n * m > 20) {
    	return;
    }
	for (int i = 0; i < n * m; i++) {
		if (mask >> i & 1) {
			cout << '+';
		} else {
			cout << '-';
		}
		if ((i + 1) % m == 0) {
			cout << endl;
		}
	}
}

inline void solve() {
  	if (n * m > 20) {
      return;
    }
	int ansab = 0, ans = -1;
	for (int i = 0; i < (1 << (n * m)); i++) {
		if (ansab < check(i)) {
			ansab = check(i);
			ans = i;
		}
	}

	cout << ansab << endl;
	out(ans);
}

int main() {
	int t;
	scanf("%d", &t);

	//precalc();
	while (t--) {
		//purify();
		read();
		solve();
	}
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &t);
  ~~~~~^~~~~~~~~~
stones.cpp: In function 'void read()':
stones.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 513 ms 376 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Incorrect 513 ms 376 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 376 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 376 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 256 KB Output is correct
3 Incorrect 513 ms 376 KB Wrong answer