Submission #168077

#TimeUsernameProblemLanguageResultExecution timeMemory
168077tincamateiRed-blue table (IZhO19_stones)C++14
100 / 100
30 ms2296 KiB
#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 (stderr)

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 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...