답안 #151303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151303 2019-09-02T12:15:34 Z hentai_lover Red-blue table (IZhO19_stones) C++14
21 / 100
88 ms 16248 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define y1 yy
#define tm hui_pizda
#define ft first
#define sd second
#define pb push_back
#define pf push_front
#define sz size()
#define cnt continue
#define m_p make_pair
#define fr(i, l, r) for(int i = l; i <= r; ++ i)
#define rf(i, r, l) for(int i = r; i >= l; -- i)
#pragma GCC optimize(-O3)
#pragma GCC optimize(Ofast)
#pragma GCC optimize("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <pii> vpi;
typedef vector <pll> vpl;

mt19937_64 rnd(time(NULL));

const ll N = 1010;
const ll oo = 1e18 + 10;
const ll mod = 1000003;

ll a[N][N], ans[N][N], kx[N], ky[N], kans, n, m, T, w;

void calc(ll n, ll m, ll s){
    bool ft = 1;
    fr(i, 1, n)fr(j, 1, m){
        if(a[i][j] < 0 && !ft){
            a[i][j] = s;
            if((i + j) % 2)s = 1 - s;
            ft = 1;
        }   else if(a[i][j] < 0){
            if((i + j) % 2 == 0)a[i][j] = s;
            else a[i][j] = 1 - s;
        }
        if(a[i][j])kx[i] ++;
        else ky[j] ++;
    }

    ll now = 0;
    fr(i, 1, n)if(kx[i] * 2 > m)now ++;
    fr(i, 1, m)if(ky[i] * 2 > n)now ++;

//    cout << endl;
//    fr(i, 1, n){
//        fr(j, 1, m)cout << a[i][j] << ' ';
//        cout << endl;
//    }
//    cout << "now: " << now << endl;
    if(now > kans){
        kans = now;
        fr(i, 1, n)fr(j, 1, m)ans[i][j] = a[i][j];
    }
    fr(i, 1, n)kx[i] = 0;
    fr(i, 1, m)ky[i] = 0;
    fr(i, 1, n)fr(j, 1, m)a[i][j] = -1;
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> T;
    while(T --){
        cin >> n >> m;
        fr(i, 1, n)fr(j, 1, m)a[i][j] = ans[i][j] = -1;
        kans = -1;

        if(n < m)w = 0;
        else w = 1;

        //0..2
        fr(i, 0, 2){
            //0..2
            fr(j, 0, 2){
                if(n < m){
                    fr(x, 1, i)fr(y, 1, n)a[y][x] = 1;
                    fr(x, 1, j)fr(y, 1, m)a[x][y] = 0;
                }   else {
                    fr(x, 1, j)fr(y, 1, m)a[x][y] = 0;
                    fr(x, 1, i)fr(y, 1, n)a[y][x] = 1;
                }
                calc(n, m, w);
            }
        }
        fr(i, 1, n)fr(j, 1, m)a[i][j] = 0;
        calc(n, m, w);
        fr(i, 1, n)fr(j, 1, m)a[i][j] = 1;
        calc(n, m, w);

        cout << kans << endl;
        fr(i, 1, n){
            fr(j, 1, m){
                if(ans[i][j] == 0)cout << '-';
                else cout << '+';
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}
/*
*/

Compilation message

stones.cpp:15:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
 #pragma GCC optimize(-O3)
                      ^
stones.cpp:16:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
 #pragma GCC optimize(Ofast)
                      ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 2380 KB Output is correct
2 Correct 77 ms 13196 KB Output is correct
3 Correct 76 ms 16248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 76 ms 2884 KB Wrong answer in test 4 4: 4 < 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 4 < 5