답안 #521637

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521637 2022-02-02T15:52:50 Z dostigator Red-blue table (IZhO19_stones) C++17
38 / 100
41 ms 1224 KB
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IShowSpeed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define mii map<int,int>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define pb push_back
#define vt vector
#define endl '\n'
#define X first
#define Y second
typedef long double ld;
typedef long long ll;
const int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},N=6e5;
const ll mod=1e9+7,inf=1e18;
int n,m;
void solve(){
    cin>>n>>m;
    if(max(n,m)<=4){
        int all=n*m;
        vt<char>ans;
        int ans1=-1;
        for(int mask=0; mask<(1<<all); ++mask){
            vt<char>var;
            int col[5]={0,0,0,0,0};
            int row[5]={0,0,0,0,0},cnt=0;
            for(int i=0; i<all; ++i){
                if((mask>>i)&1) var.pb('+');
                else var.pb('-');
            }
            int h=0;
            for(int i=0; i<n; ++i)for(int j=0; j<m; ++j){
                if(var[h]=='+'){row[i]++;}
                if(var[h]=='-'){col[j]++;}
                ++h;
            }
            for(int i=0; i<n; ++i) {if(row[i]>=(m/2)+1)++cnt;}
            for(int i=0; i<m; ++i) {if(col[i]>=(n/2)+1)++cnt;}
            if(ans1<cnt){
                ans1=cnt;
                ans=var;
            }
        }
        int h=0;
        cout<<ans1<<endl;
        for(int i=0; i<n; ++i){
            for(int j=0; j<m; ++j){
                cout<<ans[h];
                ++h;
            }
            cout<<endl;
        }
        return;
    }
    if(min(n,m)<=3){
        if(n==1){
            cout<<m<<endl;
            for(int i=1; i<=m; ++i)cout<<'-';
            cout<<endl;
            return;
        }
        if(m==1){
            cout<<n<<endl;
            for(int i=1; i<=n; ++i)cout<<'+'<<endl;
            return;
        }
        if(n==2){
            cout<<m<<endl;
            for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j){
                cout<<'-';
                if(j==m)cout<<endl;
            }
            return;
        }
        if(m==2){
            cout<<n<<endl;
            for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j){
                cout<<'+';
                if(j==m)cout<<endl;
            }
            return;
        }
        if(n==3){
            cout<<m+1<<endl;
            for(int i=1; i<=n; ++i){
                for(int j=1; j<=m; ++j){
                    if(i==2)cout<<'+';
                    else cout<<'-';
                }
                cout<<endl;
            }
            return;
        }
        if(m==3){
            cout<<n+1<<endl;
            for(int i=1; i<=n; ++i){
                for(int j=1; j<=m; ++j){
                    if(j==2)cout<<'-';
                    else cout<<'+';
                }
                cout<<endl;
            }
            return;
        }
        return;
    }
    cout<<n-1+m-1<<endl;
    for(int i=1; i<=n; ++i){
        for(int j=1; j<=m; ++j){
            if(i==n){
                cout<<'-';continue;
            }
            if(j==m){
                cout<<'+';continue;
            }
            if((i+j)%2==0) cout<<'+';
            else cout<<'-';
        }
        cout<<endl;
    }
}
int main() {
    IShowSpeed;
    int tt=1;
    cin>>tt;
    while(tt--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 21 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 21 ms 204 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Incorrect 41 ms 316 KB in the table A+B is not equal to 27
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 1224 KB Output is correct
2 Correct 19 ms 1068 KB Output is correct
3 Correct 19 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 38 ms 1220 KB in the table A+B is not equal to 46
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 21 ms 204 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Incorrect 41 ms 316 KB in the table A+B is not equal to 27
5 Halted 0 ms 0 KB -