제출 #1162963

#제출 시각아이디문제언어결과실행 시간메모리
1162963SmuggingSpunRed-blue table (IZhO19_stones)C++20
27 / 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"; } } } namespace sub2{ void solve(){ if(n == 1){ cout << m << "\n" << string(m, '-') << "\n"; } else if(m == 1){ cout << n << "\n"; for(int i = 0; i < n; i++){ cout << "+\n"; } } else if(n == 2){ cout << m << "\n" << string(m, '-') << "\n" << string(m, '-') << "\n"; } else if(m == 2){ cout << n << "\n"; for(int i = 0; i < n; i++){ cout << "++\n"; } } else if(n == 3){ cout << m + 1 << "\n" << string(m, '-') << "\n" << string(m, '-') << " " << string(m, '+') << "\n"; } else{ cout << n + 1 << "\n"; for(int i = 0; i < n; i++){ 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(); } else if(min(n, m) <= 3){ sub2::solve(); } } }

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

stones.cpp: In function 'int main()':
stones.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         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...