Submission #329126

#TimeUsernameProblemLanguageResultExecution timeMemory
329126mat_vRed-blue table (IZhO19_stones)C++14
100 / 100
81 ms9452 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; } } if(p1 == 0){ if(o){ swap(n,m); } cout << max(n,m) << "\n"; ff(i,1,n){ ff(j,1,m){ if(n > m)cout << '+'; else cout << '-'; } cout << "\n"; } return; } //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:83:9: note: in expansion of macro 'ff'
   83 |         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:84:13: note: in expansion of macro 'ff'
   84 |             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:94:5: note: in expansion of macro 'ff'
   94 |     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:95:9: note: in expansion of macro 'ff'
   95 |         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:97:5: note: in expansion of macro 'ff'
   97 |     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:99:5: note: in expansion of macro 'ff'
   99 |     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:100:5: note: in expansion of macro 'ff'
  100 |     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:107:9: note: in expansion of macro 'ff'
  107 |         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:111:9: note: in expansion of macro 'ff'
  111 |         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:123:17: note: in expansion of macro 'ff'
  123 |                 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:124:21: note: in expansion of macro 'ff'
  124 |                     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:132:17: note: in expansion of macro 'ff'
  132 |                 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:133:21: note: in expansion of macro 'ff'
  133 |                     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:139:13: note: in expansion of macro 'ff'
  139 |             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:140:17: note: in expansion of macro 'ff'
  140 |                 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...