Submission #329123

#TimeUsernameProblemLanguageResultExecution timeMemory
329123mat_vRed-blue table (IZhO19_stones)C++14
26 / 100
76 ms7916 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int mat[1005][1005]; int ans[1005][1005]; pii val[1005]; bool da[1005]; int n,m; void solve(){ cin >> n >> m; if(n == 1){ cout << m << "\n"; ff(i,1,m)cout << '-'; cout << "\n"; return; } if(m == 1){ cout << n << "\n"; ff(i,1,n)cout << "+\n"; return; } bool o = 0; if(n > m){ swap(n,m); o = 1; } int p1 = 0; int p2 = m; ff(i,1,m)val[i] = {0,i}; ff(i,1,m)da[i] = 0; vector<int> izb; ff(i,1,n){ sort(val + 1, val + m + 1); int br = (m+2)/2; br -= (izb.size()); ff(j,1,br){ val[j].xx++; } ff(j,1,m){ if(val[j].xx > (n-1)/2 && da[val[j].yy] == 0){ da[val[j].yy] = 1; val[j].xx = 1e9; izb.pb(val[j].yy); } } int tr2 = m - (izb.size()); //cout << i << " " << tr2 << "\n"; if(tr2 + i > p1 + p2){ p1 = i; p2 = tr2; } } //cout << p1 << " " << p2 << "\n"; cout << p1 + p2 << "\n"; ff(i,1,n){ ff(j,1,m)mat[i][j] = 0; } ff(i,1,m)val[i] = {0,i}; izb.clear(); ff(i,1,m)da[i] = 0; ff(i,1,n){ sort(val + 1, val + m + 1); int br = (m+2)/2; br -= (izb.size()); for(auto c:izb){ mat[i][c] = 1; } ff(j,1,br){ mat[i][val[j].yy] = 1; val[j].xx++; } ff(j,1,m){ if(val[j].xx > (n-1)/2 && da[val[j].yy] == 0){ da[val[j].yy] = 1; val[j].xx = 1e9; izb.pb(val[j].yy); } } int tr2 = m - (izb.size()); //cout << i << " " << tr2 << "\n"; if(tr2 + i == p1 + p2){ //cout << "aa\n"; if(o){ ff(k,1,n){ ff(r,1,m){ ans[r][k] = mat[k][r]^1; //ans[r][k] = ans[k][r]; } } swap(n,m); } else{ ff(k,1,n){ ff(r,1,m){ ans[k][r] = mat[k][r]; } } } ff(k,1,n){ ff(r,1,m){ if(ans[k][r] == 1)cout << '+'; else cout << '-'; } cout << "\n"; } return; } } } int main() { //ios_base::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while(t--)solve(); return 0; }

Compilation message (stderr)

stones.cpp: In function 'void solve()':
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:34:9: note: in expansion of macro 'ff'
   34 |         ff(i,1,m)cout << '-';
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:40:9: note: in expansion of macro 'ff'
   40 |         ff(i,1,n)cout << "+\n";
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:51:5: note: in expansion of macro 'ff'
   51 |     ff(i,1,m)val[i] = {0,i};
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:52:5: note: in expansion of macro 'ff'
   52 |     ff(i,1,m)da[i] = 0;
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:57:5: note: in expansion of macro 'ff'
   57 |     ff(i,1,n){
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:61:9: note: in expansion of macro 'ff'
   61 |         ff(j,1,br){
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:64:9: note: in expansion of macro 'ff'
   64 |         ff(j,1,m){
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:80:5: note: in expansion of macro 'ff'
   80 |     ff(i,1,n){
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:81:9: note: in expansion of macro 'ff'
   81 |         ff(j,1,m)mat[i][j] = 0;
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:83:5: note: in expansion of macro 'ff'
   83 |     ff(i,1,m)val[i] = {0,i};
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:85:5: note: in expansion of macro 'ff'
   85 |     ff(i,1,m)da[i] = 0;
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:86:5: note: in expansion of macro 'ff'
   86 |     ff(i,1,n){
      |     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:93:9: note: in expansion of macro 'ff'
   93 |         ff(j,1,br){
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:97:9: note: in expansion of macro 'ff'
   97 |         ff(j,1,m){
      |         ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:109:17: note: in expansion of macro 'ff'
  109 |                 ff(k,1,n){
      |                 ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:110:21: note: in expansion of macro 'ff'
  110 |                     ff(r,1,m){
      |                     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:118:17: note: in expansion of macro 'ff'
  118 |                 ff(k,1,n){
      |                 ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:119:21: note: in expansion of macro 'ff'
  119 |                     ff(r,1,m){
      |                     ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'k' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:125:13: note: in expansion of macro 'ff'
  125 |             ff(k,1,n){
      |             ^~
stones.cpp:6:27: warning: unnecessary parentheses in declaration of 'r' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
stones.cpp:126:17: note: in expansion of macro 'ff'
  126 |                 ff(r,1,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...