Submission #329121

# Submission time Handle Problem Language Result Execution time Memory
329121 2020-11-19T09:43:54 Z mat_v Red-blue table (IZhO19_stones) C++14
15 / 100
72 ms 6892 KB
#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;
    }
    int p1 = 0;
    int p2 = m;
        bool o = 0;
      if(n > m){
        swap(n,m);
        o = 1;
    }
    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[r][k] = mat[r][k];
                    }
                }
            }

            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

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:50:5: note: in expansion of macro 'ff'
   50 |     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:51:5: note: in expansion of macro 'ff'
   51 |     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:56:5: note: in expansion of macro 'ff'
   56 |     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:60:9: note: in expansion of macro 'ff'
   60 |         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:63:9: note: in expansion of macro 'ff'
   63 |         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:79:5: note: in expansion of macro 'ff'
   79 |     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:80:9: note: in expansion of macro 'ff'
   80 |         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:82:5: note: in expansion of macro 'ff'
   82 |     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:84:5: note: in expansion of macro 'ff'
   84 |     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:85:5: note: in expansion of macro 'ff'
   85 |     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:92:9: note: in expansion of macro 'ff'
   92 |         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:96:9: note: in expansion of macro 'ff'
   96 |         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:108:17: note: in expansion of macro 'ff'
  108 |                 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:109:21: note: in expansion of macro 'ff'
  109 |                     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:117:17: note: in expansion of macro 'ff'
  117 |                 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:118:21: note: in expansion of macro 'ff'
  118 |                     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:124:13: note: in expansion of macro 'ff'
  124 |             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:125:17: note: in expansion of macro 'ff'
  125 |                 ff(r,1,m){
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 620 KB in the table A+B is not equal to 46
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 2432 KB in the table A+B is not equal to 78
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 2540 KB Output is correct
2 Correct 70 ms 6892 KB Output is correct
3 Correct 72 ms 5740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Wrong answer