Submission #206534

# Submission time Handle Problem Language Result Execution time Memory
206534 2020-03-03T17:38:49 Z bash Red-blue table (IZhO19_stones) C++17
100 / 100
50 ms 2296 KB
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
 
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
 
const long long MXN = 1e5 + 10;
const long long MNN = 1e4 + 520;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9;
 
typedef long long llong;
typedef unsigned long long ullong;
 
using namespace std;
 
int n, m;
bool ans[1010][1010];
int cnt[1010];
 
int sum1(int n, int m){
    int sum = n;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            ans[i][j] = 1;
        }
        cnt[i] = m;
    }
    int last = 1;
    for(int i = 1; i <= m; i++){
        int lol = n / 2 + 1;
        int cur = last;
        while(lol != 0){
            if(cnt[cur] > m / 2 + 1){
                ans[cur][i] = 0;
                cnt[cur]--;
                lol--;
            }
            cur++;
            if(cur == n + 1){
                cur = 1;
            }
            if(cur == last) break;
        }
        if(lol != 0) break;
        else {
            sum++;
            last = cur;
        }
    }
    return sum;
}
 
int sum2(int n, int m){
    int sum = m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            ans[i][j] = 0;
            cnt[j] = n;
        }
    }
    int last = 1;
    for(int i = 1; i <= n; i++){
        int lol = m / 2 + 1;
        int cur = last;
        while(lol != 0){
            if(cnt[cur] > n / 2 + 1){
                cnt[cur]--;
                ans[i][cur] = 1;
                lol--;
            }
            cur++;
            if(cur == m + 1){
                cur = 1;
            }
            if(cur == last) break;
        }
        if(lol == 0) {
            sum++;
            last = cur;
        }
        else break;
    }
    return sum;
}
 
void output(int n, int m){
    if(sum1(n, m) >= sum2(n, m)){
        cout << sum1(n, m) << nl;
    }else{
        cout << sum2(n, m) << nl;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cout << (ans[i][j] == 1 ? '+' : '-');
        }
        cout << nl;
    }
}
 
int main(){
    int t;
    cin >> t;
    while(t--){
        cin >> n >> m;
        output(n, m);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1528 KB Output is correct
2 Correct 42 ms 2040 KB Output is correct
3 Correct 40 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1528 KB Output is correct
2 Correct 39 ms 1916 KB Output is correct
3 Correct 34 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 8 ms 408 KB Output is correct
5 Correct 50 ms 1528 KB Output is correct
6 Correct 42 ms 2040 KB Output is correct
7 Correct 40 ms 2172 KB Output is correct
8 Correct 44 ms 1528 KB Output is correct
9 Correct 39 ms 1916 KB Output is correct
10 Correct 34 ms 1656 KB Output is correct
11 Correct 16 ms 636 KB Output is correct
12 Correct 36 ms 1912 KB Output is correct
13 Correct 38 ms 2040 KB Output is correct
14 Correct 32 ms 1656 KB Output is correct
15 Correct 45 ms 2296 KB Output is correct
16 Correct 36 ms 1912 KB Output is correct
17 Correct 17 ms 1272 KB Output is correct