Submission #168077

# Submission time Handle Problem Language Result Execution time Memory
168077 2019-12-11T09:14:12 Z tincamatei Red-blue table (IZhO19_stones) C++14
100 / 100
30 ms 2296 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 1000;
char matr[MAX_N][MAX_N];

int main() {
	int T, N, M;
	scanf("%d", &T);
	while(T--) {
		int best = 0, bestFR = -1, bestFC = -1;

		scanf("%d%d", &N, &M);

		int reqPerRow = M / 2 + 1, reqPerCol = N / 2 + 1;
        int freePerRow = M - reqPerRow;

		for(int fixedRows = 0; fixedRows <= N; ++fixedRows)
			for(int fixedCols = 0; fixedCols <= M; ++fixedCols) {
				int reqCol = max(0, reqPerCol - (N - fixedRows));
				int reqRow = max(0, reqPerRow - (M - fixedCols));

				if((long long)reqRow * fixedRows + (long long)reqCol * fixedCols <= (long long)fixedCols * fixedRows && fixedRows + fixedCols > best) {
					best = fixedRows + fixedCols;
					bestFR = fixedRows;
					bestFC = fixedCols;
				}
			}

		int lastP = 0;
		for(int l = 0; l < N; ++l)
			for(int c = 0; c < M; ++c)
				matr[l][c] = '-';

        int reqRow = max(0, reqPerRow - (M - bestFC));
		for(int l = 0; l < bestFR; ++l) {
			for(int c = bestFC; c < M; ++c)
                matr[l][c] = '+';
            for(int c = 0; c < bestFC && c < reqRow; ++c) {
                matr[l][lastP] = '+';
                lastP = (lastP + 1) % bestFC;
            }
        }

		printf("%d\n", best);
		for(int l = 0; l < N; ++l) {
			for(int c = 0; c < M; ++c)
				fputc(matr[l][c], stdout);
			printf("\n");
		}
	}
	return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:17:13: warning: unused variable 'freePerRow' [-Wunused-variable]
         int freePerRow = M - reqPerRow;
             ^~~~~~~~~~
stones.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &T);
  ~~~~~^~~~~~~~~~
stones.cpp:14:8: 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 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory 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 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1468 KB Output is correct
2 Correct 26 ms 1912 KB Output is correct
3 Correct 25 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1532 KB Output is correct
2 Correct 24 ms 1876 KB Output is correct
3 Correct 22 ms 1656 KB Output is correct
# Verdict Execution time Memory 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 4 ms 376 KB Output is correct
5 Correct 30 ms 1468 KB Output is correct
6 Correct 26 ms 1912 KB Output is correct
7 Correct 25 ms 2160 KB Output is correct
8 Correct 29 ms 1532 KB Output is correct
9 Correct 24 ms 1876 KB Output is correct
10 Correct 22 ms 1656 KB Output is correct
11 Correct 9 ms 632 KB Output is correct
12 Correct 23 ms 1912 KB Output is correct
13 Correct 24 ms 2040 KB Output is correct
14 Correct 19 ms 1784 KB Output is correct
15 Correct 29 ms 2296 KB Output is correct
16 Correct 22 ms 1940 KB Output is correct
17 Correct 11 ms 1272 KB Output is correct