Submission #338945

# Submission time Handle Problem Language Result Execution time Memory
338945 2020-12-24T10:20:07 Z jenkinsser Red-blue table (IZhO19_stones) C++17
100 / 100
81 ms 2284 KB
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define st first
#define nd second
#define pii pair<int,int>
#define N 200005
#define INF 1000000005
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) (x).begin(),(x).end()
#define ll long long
#define int ll
using namespace std;

int n,m,ans;
int cnt[N];

void solve(){
    cin >> n >> m;
    char table[n+1][m+1];
    int ans;
    if(n>=m){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                table[i][j]='+';
            }
        }
        ans=n;
        int cur=1;
        int l=(n*((m-1)/2))/(n/2+1);
        for(int i=1;i<=n;i++){
            for(int j=1;j<=(m-1)/2;j++){
                table[i][cur]='-';
                cnt[cur]++;
                cur++;
                if(cur-1==l) cur=1;
            }
        }
        for(int i=1;i<=l;i++){
            if(cnt[i]>=n/2+1){
                ans++;
            }
            cnt[i]=0;
        }
    }
    else{
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                table[i][j]='-';
            }
        }
        ans=m;
        int cur=1;
        int l=(m*((n-1)/2))/(m/2+1);
        for(int i=1;i<=m;i++){
            for(int j=1;j<=(n-1)/2;j++){
                table[cur][i]='+';
                cnt[cur]++;
                cur++;
                if(cur-1==l) cur=1;
            }
        }
        for(int i=1;i<=l;i++){
            if(cnt[i]>=m/2+1){
                ans++;
            }
            cnt[i]=0;
        }
    }
    cout << ans << endl;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout << table[i][j];
        }
        cout << endl;
    }
}

int32_t main(){
    fastio()
    int t=1;
    cin >> t;
    while(t--)
        solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 10 ms 364 KB Output is correct
4 Correct 18 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 1388 KB Output is correct
2 Correct 43 ms 1900 KB Output is correct
3 Correct 34 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 63 ms 1388 KB Output is correct
2 Correct 34 ms 1644 KB Output is correct
3 Correct 30 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 10 ms 364 KB Output is correct
4 Correct 18 ms 364 KB Output is correct
5 Correct 81 ms 1388 KB Output is correct
6 Correct 43 ms 1900 KB Output is correct
7 Correct 34 ms 1900 KB Output is correct
8 Correct 63 ms 1388 KB Output is correct
9 Correct 34 ms 1644 KB Output is correct
10 Correct 30 ms 1388 KB Output is correct
11 Correct 41 ms 620 KB Output is correct
12 Correct 32 ms 1516 KB Output is correct
13 Correct 37 ms 1516 KB Output is correct
14 Correct 28 ms 1132 KB Output is correct
15 Correct 42 ms 2284 KB Output is correct
16 Correct 28 ms 1772 KB Output is correct
17 Correct 13 ms 1004 KB Output is correct