Submission #167720

# Submission time Handle Problem Language Result Execution time Memory
167720 2019-12-09T19:10:38 Z beso123 Red-blue table (IZhO19_stones) C++14
100 / 100
136 ms 9208 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int t;
bool sort21(pair<int,int> a,pair<int,int> b){
    return a.first<b.first;
}
main(){
cin>>t;
while(t--){
    int n,m;
    cin>>n>>m;
    int M=(n/2)+1;
    int N=(m/2)+1;
    int a[n+1][m+1];
    int b[max(n,m)+1];
    for(int k=1;k<=max(n,m);k++)
        b[k]=0;
    for(int k=1;k<=n;k++){

        for(int i=1;i<=m;i++)
            a[k][i]=0;
    }
    if(n>=m){
    int ans=n;
    for(int i=1;i<=m;i++){
            vector<pair<int,int> > v;
        for(int k=1;k<=n;k++){
            v.push_back({b[k],k});
        }
        sort(v.begin(),v.end(),sort21);
        if(v[M-1].first<m-N){
            ans++;
        for(int k=0;k<M;k++){
            a[v[k].second][i]=1;
            b[v[k].second]++;
        }
    }
    else break;
    }
    cout<<ans<<endl;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=m;i++)
            if(a[k][i])
            cout<<'-';
        else cout<<'+';
        cout<<endl;
    }
    }
    else{
           int ans=m;
    for(int i=1;i<=n;i++){
            vector<pair<int,int> > v;
        for(int k=1;k<=m;k++){
            v.push_back({b[k],k});
        }
        sort(v.begin(),v.end(),sort21);
        if(v[N-1].first<n-M){
            ans++;
        for(int k=0;k<N;k++){
            a[i][v[k].second]=1;
            b[v[k].second]++;
        }
    }
    else break;
    }
    cout<<ans<<endl;
    for(int k=1;k<=n;k++){
        for(int i=1;i<=m;i++)
            if(a[k][i])
            cout<<'+';
        else cout<<'-';
        cout<<endl;
    }
    }
}

return 0;
}

Compilation message

stones.cpp:8:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 15 ms 376 KB Output is correct
4 Correct 25 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 136 ms 1468 KB Output is correct
2 Correct 89 ms 6520 KB Output is correct
3 Correct 88 ms 6904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 1528 KB Output is correct
2 Correct 88 ms 5256 KB Output is correct
3 Correct 72 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 15 ms 376 KB Output is correct
4 Correct 25 ms 428 KB Output is correct
5 Correct 136 ms 1468 KB Output is correct
6 Correct 89 ms 6520 KB Output is correct
7 Correct 88 ms 6904 KB Output is correct
8 Correct 105 ms 1528 KB Output is correct
9 Correct 88 ms 5256 KB Output is correct
10 Correct 72 ms 3708 KB Output is correct
11 Correct 59 ms 544 KB Output is correct
12 Correct 81 ms 4600 KB Output is correct
13 Correct 89 ms 3704 KB Output is correct
14 Correct 59 ms 2552 KB Output is correct
15 Correct 111 ms 9208 KB Output is correct
16 Correct 69 ms 6904 KB Output is correct
17 Correct 35 ms 3192 KB Output is correct