Submission #344085

#TimeUsernameProblemLanguageResultExecution timeMemory
344085NurlykhanRed-blue table (IZhO19_stones)C++17
100 / 100
81 ms2412 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1024; int t; int n, m; bool a[N][N], ans[N][N]; int cnt() { int res = 0; for (int i = 0; i < n; i++) { int s = 0; for (int j = 0; j < m; j++) { if (a[i][j]) s++; else s--; } if (s > 0) res++; } for (int j = 0; j < m; j++) { int s = 0; for (int i = 0; i < n; i++) { if (a[i][j]) s++; else s--; } if (s < 0) res++; } return res; } void solve() { int mx = 0; for (int mask = 0; mask < (1 << (n * m)); mask++) { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if ((mask >> (i * m + j)) % 2) { a[i][j] = 1; } else { a[i][j] = 0; } } } int cur = cnt(); if (cur > mx) { mx = cur; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { ans[i][j] = a[i][j]; } } } } printf("%d\n", mx); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (ans[i][j]) printf("+"); else printf("-"); } printf("\n"); } } int s[N]; void tupo() { bool boo = 0; if (n > m) { swap(n, m); boo = 1; } int ans = m; for (int j = 0; j < m; j++) { s[j] = -n; } for (int i = 0; i < n; i++) { vector<pair<int, int> > v; for (int j = 0; j < m; j++) { a[i][j] = 0; v.push_back(make_pair(s[j], j)); } sort(v.begin(), v.end()); bool ok = 1; for (int j = 0; j < m / 2 + 1; j++) { if (v[j].first + 2 >= 0) ok = 0; } if (ok) { ans++; for (int j = 0; j < m / 2 + 1; j++) { s[v[j].second] += 2; a[i][v[j].second] = 1; } } } printf("%d\n", ans); if (boo) { for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { if (!a[i][j]) printf("+"); else printf("-"); } printf("\n"); } } else { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j]) printf("+"); else printf("-"); } printf("\n"); } } } int main() { scanf("%d", &t); while (t--) { scanf("%d%d", &n, &m); tupo(); } return 0; }

Compilation message (stderr)

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