Submission #173282

# Submission time Handle Problem Language Result Execution time Memory
173282 2020-01-03T17:42:30 Z GoldeN Red-blue table (IZhO19_stones) C++17
100 / 100
40 ms 2372 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <vector <int> > vvi;
typedef vector <vector <ll> > vvl;
typedef vector <pair<int,int> > vii;
typedef vector <pair<ll,ll> > vll;

string itos(int n) {stringstream ss;ss<<n;string s=ss.str();return s;}

ll ppow(ll x,ll y,ll mod) {
    ll res=1;
    while(y) {
        if(y&1) res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}

const int N=1005;

char a[N][N];
int cnt[N];

int solve1(int n,int m) {
    int res=m;
    for (int i=1;i<=n;++i) {
        for (int j=1;j<=m;++j) {
            a[i][j]='-';
            cnt[j]=n;
        }
    }
    int last=1;
    for (int i=1;i<=n;++i) {
        int cur=last;
        int need=m/2+1;
        while (need) {
            if (cnt[cur] > n/2+1) {
                cnt[cur]--;
                a[i][cur]='+';
                need--;
            }
            cur++;
            if (cur == m+1) {
                cur=1;
            }
            if (cur == last) break;
        }
        if (need == 0) {
            res++;
            last=cur;
        }
        else
            break;
    }
    return res;
}

int solve2(int n,int m) {
    int res=n;
    for (int i=1;i<=n;++i) {
        for (int j=1;j<=m;++j) {
            a[i][j]='+';
        }
        cnt[i]=m;
    }
    int last=1;
    for (int i=1;i<=m;++i) {
        int cur=last;
        int need=n/2+1;
        while (need) {
            if (cnt[cur] > m/2+1) {
                cnt[cur]--;
                a[cur][i]='-';
                need--;
            }
            cur++;
            if (cur == n+1) {
                cur=1;
            }
            if (cur == last) break;
        }
        if (need == 0) {
            res++;
            last=cur;
        }
        else
            break;
    }
    return res;
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int n,m;
        cin >> n >> m;
        if (solve1(n,m) > solve2(n,m)) {
            cout << solve1(n,m) << "\n";
        }
        else {
            cout << solve2(n,m) << "\n";
        }
        for (int i=1;i<=n;++i) {
            for (int j=1;j<=m;++j) {
                cout << a[i][j];
            }
            cout << "\n";
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1532 KB Output is correct
2 Correct 36 ms 2040 KB Output is correct
3 Correct 33 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 1528 KB Output is correct
2 Correct 31 ms 1836 KB Output is correct
3 Correct 28 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 33 ms 1532 KB Output is correct
6 Correct 36 ms 2040 KB Output is correct
7 Correct 33 ms 2168 KB Output is correct
8 Correct 32 ms 1528 KB Output is correct
9 Correct 31 ms 1836 KB Output is correct
10 Correct 28 ms 1656 KB Output is correct
11 Correct 10 ms 632 KB Output is correct
12 Correct 31 ms 1948 KB Output is correct
13 Correct 31 ms 2040 KB Output is correct
14 Correct 25 ms 1788 KB Output is correct
15 Correct 40 ms 2372 KB Output is correct
16 Correct 27 ms 1912 KB Output is correct
17 Correct 14 ms 1276 KB Output is correct