제출 #1162955

#제출 시각아이디문제언어결과실행 시간메모리
1162955SmuggingSpunRed-blue table (IZhO19_stones)C++20
17 / 100
11 ms328 KiB
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
template<class T>bool maximize(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
int n, m;
namespace sub1{
    void solve(){
        vector<vector<char>>best;
        int opt = 0;
        for(int mask = (1 << (n * m)) - 1; mask > -1; mask--){
            vector<vector<char>>state(n, vector<char>(m));
            int cur_opt = 0;
            for(int i = 0, p = 0; i < n; i++){
                int cnt = 0;
                for(int j = 0; j < m; j++, p++){
                    cnt += int((state[i][j] = ((1 << p & mask) ? '+' : '-')) == '+'); 
                }
                if(cnt > (m >> 1)){
                    cur_opt++;
                }
            }
            for(int j = 0; j < m; j++){
                int cnt = 0;
                for(int i = 0; i < n; i++){
                    cnt += int(state[i][j] == '-');
                }
                if(cnt > (n >> 1)){
                    cur_opt++;
                }
            }
            if(maximize(opt, cur_opt)){
                best = state;
            }
        }
        cout << opt << "\n";
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                cout << best[i][j];
            }
            cout << "\n";
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
    }
    int _t;
    cin >> _t;
    for(int _ = 0; _ < _t; _++){
        cin >> n >> m;
        if(_t <= 16 && n * m <= 16){
            sub1::solve();
        }
    }
}

컴파일 시 표준 에러 (stderr) 메시지

stones.cpp: In function 'int main()':
stones.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...