Submission #395736

#TimeUsernameProblemLanguageResultExecution timeMemory
395736peuchRed-blue table (IZhO19_stones)C++17
100 / 100
129 ms2244 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 1010; int t; int n, m; int k, l; int ans; int in[MAXN]; char grid[MAXN][MAXN]; bool inv; set<pair<int, int> > s; int main(){ scanf("%d", &t); while(t--){ s.clear(); scanf("%d %d", &n, &m); if(n < m) swap(n, m), inv = true; else inv = false; k = n / 2 + 1; l = m / 2 + 1; ans = n; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++) grid[i][j] = (inv) ? '-' : '+'; s.insert(make_pair(-m, i)); in[i] = m; } for(int j = 1; j <= m; j++){ vector<int> ids; bool flag = false; for(int _ = 0; _ < k; _++){ ids.push_back(s.begin()->second); if(s.begin()->first == -l) flag = true; s.erase(s.begin()); } if(flag) break; ans++; for(int i = 0; i < ids.size(); i++){ int cur = ids[i]; in[cur]--; s.insert(make_pair(-in[cur], cur)); grid[cur][j] = (inv) ? '+' : '-'; } } printf("%d\n", ans); if(inv) swap(n, m); for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ printf("%c", (inv) ? grid[j][i] : grid[i][j]); } printf("\n"); } } }

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    for(int i = 0; i < ids.size(); i++){
      |                   ~~^~~~~~~~~~~~
stones.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
stones.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   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...