Submission #991563

# Submission time Handle Problem Language Result Execution time Memory
991563 2024-06-02T13:01:48 Z Mardonbekhazratov Red-blue table (IZhO19_stones) C++17
100 / 100
64 ms 2280 KB
#include<bits/stdc++.h>
using namespace std;

void solve(){
    int n,m;
    cin>>n>>m;
    vector<string>a;
    if(n>=m){
        a.assign(n,string(m,'+'));
        vector<int>b(n,0);
        for(int i=0;i<m;i++){
            set<pair<int,int>>s;
            for(int j=0;j<n;j++) s.insert({b[j],j});
            for(int j=0;j<n/2+1;j++){
                auto x=*s.begin();
                s.erase(s.begin());
                if(x.first>=(m-1)/2) break;
                b[x.second]++;
                a[x.second][i]='-';
            }
        }
    }
    else{
        a.assign(n,string(m,'-'));
        vector<int>b(m,0);
        for(int i=0;i<n;i++){
            set<pair<int,int>>s;
            for(int j=0;j<m;j++) s.insert({b[j],j});
            for(int j=0;j<m/2+1;j++){
                auto x=*s.begin();
                s.erase(s.begin());
                if(x.first>=(n-1)/2) break;
                b[x.second]++;
                a[i][x.second]='+';
            }
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int c=0;
        for(int j=0;j<m;j++){
            if(a[i][j]=='+') c++;
        }
        if(c>m/2) ans++;
    }
    for(int i=0;i<m;i++){
        int c=0;
        for(int j=0;j<n;j++){
            if(a[j][i]=='-') c++;
        }
        if(c>n/2) ans++;
    }
    cout<<ans<<'\n';
    for(int i=0;i<n;i++){
        cout<<a[i]<<'\n';
    }
}

signed main(){
    int t=1;
    cin>>t;
    while(t--){
        solve();
        cout<<'\n';
    }
    return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1360 KB Output is correct
2 Correct 52 ms 1872 KB Output is correct
3 Correct 64 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1360 KB Output is correct
2 Correct 44 ms 1632 KB Output is correct
3 Correct 39 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 6 ms 348 KB Output is correct
5 Correct 48 ms 1360 KB Output is correct
6 Correct 52 ms 1872 KB Output is correct
7 Correct 64 ms 1876 KB Output is correct
8 Correct 48 ms 1360 KB Output is correct
9 Correct 44 ms 1632 KB Output is correct
10 Correct 39 ms 1356 KB Output is correct
11 Correct 11 ms 604 KB Output is correct
12 Correct 43 ms 1540 KB Output is correct
13 Correct 45 ms 1360 KB Output is correct
14 Correct 33 ms 1112 KB Output is correct
15 Correct 59 ms 2280 KB Output is correct
16 Correct 43 ms 1876 KB Output is correct
17 Correct 19 ms 1112 KB Output is correct