Submission #395743

#TimeUsernameProblemLanguageResultExecution timeMemory
395743ly20Red-blue table (IZhO19_stones)C++17
0 / 100
69 ms1844 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1123; int tb[MAXN][MAXN]; int sl[MAXN], sc[MAXN]; int n, m; bool teste(int a, int b) { if(a > n || b > m) return false; for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { tb[i][j] = 0; sl[i] = m; sc[j] = 0; } } bool ok = true; for(int i = n; i > n - a; i--) { for(int j = 1; j <= m; j++) { tb[i][j] = 1; sl[i]--; sc[j]++; } } for(int j = m; j > m - a; j--) { for(int i = n; i >= 1; i--) { tb[i][j] = 0; sl[i]++; sc[j]--; } } int l = n - a, c = m - b; int liml = m / 2 + 1, limc = n / 2 + 1; if(l == 0 || c == 0) return true; for(int i = 1; i <= l; i++) { int qtdisp = sl[i] - liml; for(int j = 1; j <= c; j++) { if(qtdisp > 0 && sc[j] < limc) { qtdisp--; sc[j]++; tb[i][j] = 1; sl[i]--; } } } for(int i = 1; i <= c; i++) if(sc[i] < limc) ok = false; return ok; } int main() { int t; scanf("%d", &t); while(t--) { scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { tb[i][j] = 0; sl[i] = m; sc[j] = 0; } } if(n == 1) { printf("%d\n", m); for(int i = 0; i < m; i++) printf("-"); printf("\n"); continue; } else if(m == 1) { printf("%d\n", n); for(int i = 0; i < n; i++) printf("+\n"); continue; } bool ok = false; int resp = 0; for(int i = 1; i < 5; i++) { for(int j = 0; j <= i; j++) { if(ok) continue; ok = teste(j, i - j); if(ok) resp = i; } } printf("%d\n", m + n - resp); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { if(tb[i][j] == 0) printf("+"); else printf("-"); } printf("\n"); } } }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
stones.cpp:52:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |         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...