답안 #424192

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424192 2021-06-11T17:52:09 Z doowey Red-blue table (IZhO19_stones) C++14
100 / 100
67 ms 3272 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 1010;


vector<vector<char>> get(int n, int m, int &sol){
    vector<vector<char>> sos;
    sos.resize(n);
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0 ; j < m ; j ++ ){
            sos[i].push_back('-');
        }
    }
    for(int i = 0 ; i < n; i ++ ){
        for(int j = 0; j < (m + 2) / 2; j ++ ){
            sos[i][j] = '+';
        }
    }
    int xx;
    int take;
    for(int jj = 0 ; jj < (m + 2) / 2; jj ++ ){
        if((jj + 1) * ((n + 2) / 2) > ((m - 1) / 2) * ((n - 1) / 2))
            break;
        xx = jj-1;
        for(int id = 0; id < (n + 2) / 2; id ++ ){
            xx ++ ;
            xx %= (m - 1)/2;
            sos[id][jj] = '-';
            sos[id][xx+(m+2)/2] = '+';
        }
    }
    sol = 0;
    int cnt;
    for(int i = 0 ; i < n; i ++ ){
        cnt = 0;
        for(int j = 0 ; j < m ; j ++ ){
            if(sos[i][j] == '+'){
                cnt ++ ;
            }
        }
        if(cnt >= (m + 2) / 2){
            sol ++ ;
        }
    }
    for(int j = 0 ; j < m ; j ++ ){
        cnt = 0;
        for(int i = 0 ; i < n; i ++ ){
            if(sos[i][j] == '-'){
                cnt ++ ;
            }
        }
        if(cnt >= (n + 2) / 2){
            sol ++ ;
        }
    }
    return sos;
}

void solve(){
    int n, m;
    cin >> n >> m;
    int res1 = 0;
    int res2 = 0;
    vector<vector<char>> s1 = get(n, m, res1);
    vector<vector<char>> s2 = get(m, n, res2);
    if(res1 >= res2){
        cout << res1 << "\n";
        for(auto x : s1){
            for(auto y : x){
                cout << y;
            }
            cout << "\n";
        }
    }
    else{
        cout << res2 << "\n";
        for(int i = 0 ; i < n; i ++ ){
            for(int j = 0 ; j < m ; j ++ ){
                if(s2[j][i] == '-'){
                    s2[j][i] = '+';
                }
                else{
                    s2[j][i] = '-';
                }
                cout << s2[j][i];
            }
            cout << "\n";
        }

    }
}

int main(){
    fastIO;
    //freopen("in.txt","r",stdin);
    int tc;
    cin >> tc;
    for(int iq = 1; iq <= tc; iq ++ ){
        solve();
    }
    return 0;
}

Compilation message

stones.cpp: In function 'std::vector<std::vector<char> > get(int, int, int&)':
stones.cpp:30:9: warning: unused variable 'take' [-Wunused-variable]
   30 |     int take;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 1332 KB Output is correct
2 Correct 56 ms 2644 KB Output is correct
3 Correct 53 ms 2868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 1376 KB Output is correct
2 Correct 57 ms 2396 KB Output is correct
3 Correct 54 ms 2208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 6 ms 368 KB Output is correct
5 Correct 67 ms 1332 KB Output is correct
6 Correct 56 ms 2644 KB Output is correct
7 Correct 53 ms 2868 KB Output is correct
8 Correct 63 ms 1376 KB Output is correct
9 Correct 57 ms 2396 KB Output is correct
10 Correct 54 ms 2208 KB Output is correct
11 Correct 18 ms 576 KB Output is correct
12 Correct 46 ms 2428 KB Output is correct
13 Correct 53 ms 1888 KB Output is correct
14 Correct 46 ms 1244 KB Output is correct
15 Correct 59 ms 3272 KB Output is correct
16 Correct 47 ms 2732 KB Output is correct
17 Correct 23 ms 1480 KB Output is correct