이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
int n, m;
int calc(vector<vector<int> > &a){
int all = 0;
for(int i = 0;i < n; i++){
int blue = 0;
for(int j = 0;j < m; j++){
blue+= a[i][j];
}
if(blue >= m-(m / 2) and blue > m/2) all++;
}
for(int j = 0;j < m; j++){
int red = 0;
for(int i = 0;i < n; i++){
red+= (a[i][j] == 0);
}
if(red >= n-(n / 2) and red > n/2) all++;
}
return all;
}
void solve(){
cin >> n >> m;
vector< vector<int> > a(n, vector<int>(m));
int answer = 0, s = 0, MASK=0;
vector<pair<int,int>> cell(n*m);
for(int i = 0;i < n; i++){
for(int j = 0;j < m; j++){
cell[s] = {i, j};
s++;
}
}
for(int mask = 0; mask < (1<<(n*m)); mask++){
for(int i = 0;i < n*m; i++){
if(mask & (1<<i)){
a[cell[i].ff][cell[i].ss] = 1;
}else{
a[cell[i].ff][cell[i].ss] = 0;
}
}
int S = calc(a);
if(answer < S){
answer = S;
MASK = mask;
}
}
for(int i = 0;i < n*m; i++){
if(MASK & (1<<i)){
a[cell[i].ff][cell[i].ss] = 1;
}else{
a[cell[i].ff][cell[i].ss] = 0;
}
}
cout << answer << '\n';
for(int i = 0;i < n; i++){
for(int j = 0;j < m; j++){
cout << (a[i][j] ? '+' : '-');
}
cout << '\n';
}
}
main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--){
solve();
// cout << '\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stones.cpp:74:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
74 | main(){
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |