답안 #599283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599283 2022-07-19T12:21:30 Z M_W Red-blue table (IZhO19_stones) C++17
17 / 100
2000 ms 10316 KB
#include <bits/stdc++.h>
using namespace std;
int a[1010][1010];
int main(){
    int T;
    scanf("%d", &T);

    vector<vector<int>> v;
    v.push_back({0}); v.push_back({1});
    for(int i = 1; i < 16; i++){
        vector<vector<int>> tmp = v;
        v.clear();
        for(auto t : tmp){
            vector<int> tt = t;
            tt.push_back(0);
            v.push_back(tt);

            tt.pop_back();
            tt.push_back(1);
            v.push_back(tt);
        }
    }
    while(T--){
        int N, M, state = 0;
        scanf("%d %d", &N, &M);

        vector<int> ans; int mx = 0;
        for(auto x : v){
            for(int i = 0; i < N; i++){
                for(int j = 0; j < M; j++){
                    a[i][j] = x[(i * M) + j];
                }
            }
            int cnt = 0;
            for(int i = 0; i < N; i++){
                int red = 0, blue = 0;
                for(int j = 0; j < M; j++){
                    if(a[i][j]) red++;
                    else blue++;
                }
                if(red > blue) cnt++;
            }

            for(int j = 0; j < M; j++){
                int red = 0, blue = 0;
                for(int i = 0; i < N; i++){
                    if(a[i][j]) red++;
                    else blue++;
                }
                if(blue > red) cnt++;
            }

            if(cnt > mx){
                mx = cnt;
                ans = x;
            }
        }
        printf("%d\n", mx);
        for(int i = 0; i < N; i++){
            for(int j = 0; j < M; j++){
                printf(ans[(i * M) + j] ? "+" : "-");
            }
            printf("\n");
        }
    }
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:24:19: warning: unused variable 'state' [-Wunused-variable]
   24 |         int N, M, state = 0;
      |                   ^~~~~
stones.cpp:6:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    6 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~
stones.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d %d", &N, &M);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10268 KB Output is correct
2 Correct 77 ms 10316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2070 ms 10260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10268 KB Output is correct
2 Correct 77 ms 10316 KB Output is correct
3 Execution timed out 2070 ms 10260 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2025 ms 10304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2062 ms 10268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10268 KB Output is correct
2 Correct 77 ms 10316 KB Output is correct
3 Execution timed out 2070 ms 10260 KB Time limit exceeded
4 Halted 0 ms 0 KB -