답안 #457632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
457632 2021-08-07T09:06:03 Z Aldas25 Coins (LMIO19_monetos) C++14
8.97814 / 100
2000 ms 988 KB
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 1000100, MAXK = 60;
//const ll MOD = 998244353;
const ll MOD = 1e9+7;
const ll INF = 1e17;

int t, n, k1, k2;

bool grid[310][310], cur[310][310], ans[310][310];
int mn = 310*310;
int i, j;

void printCur () {
    cout << " printing cur" << "\n";
    FOR(i, 0, n-1){
        FOR(j, 0, n-1) cout << cur[i][j] << " ";
        cout << "\n";
    }
    cout << endl;
}

int cr;

void eval () {
    cr = 0;
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) cr += (!grid[i][j] && cur[i][j]);
    if (cr < mn) {
        mn = cr;
        FOR(i, 0, n-1) FOR(j, 0, n-1) ans[i][j] = cur[i][j];
    }

    //cout << " evaled cur, cr = " << cr << endl;
    //printCur();
}

void sol1 () {
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        if (i < (n/2)) cur[i][j] = false;
        else cur[i][j] = true;
    }
    eval();
}

void sol2 () {
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        if (j < (n/2)) cur[i][j] = false;
        else cur[i][j] = true;
    }
    eval();
}


void sol3 () {
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        if (j < (n-i)) cur[i][j] = false;
        else cur[i][j] = true;
    }
    for(i = 0; i < (n/2); i++) {
        cur[i][n-i-1] = true;
    }
    eval();
}

void sol4 () {
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        if (j < (n-i)) cur[i][j] = false;
        else cur[i][j] = true;
    }
    for(i = (n/2); i < n; i++) {
        cur[i][n-i-1] = true;
    }
    eval();
}

void sol5 () {
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) {
        if (j < (n-i)) cur[i][j] = false;
        else cur[i][j] = true;
    }
    for(i = 0; i < n; i++) {
        if (i%2 == 0) cur[i][n-i-1] = true;
    }
    eval();
}

int h[310];
int range, id, fl, s;

void sol6() {
    s = n*n / 2;

    for(i = 0; i < n; i++) h[i] = n;
    for (i = 0; i < n; i++) for (j = 0; j < n; j++) cur[i][j] = false;

    fl = 0;

    while (s > 0) {
        range = min(s, n);
        id = rng() % range;
        id = n-1-id - fl;

        for (j = id; j < n; j++) {
            if (h[j] == 0) continue;
            s--;
            h[j]--;
            cur[h[j]][j] = true;
            if (h[j] == 0) fl++;
        }
    }

    eval();
}

int main()
{
    FAST_IO;

    cin >> t >> n >> k1 >> k2;

    for (i = 0; i < n; i++) for (j = 0; j < n; j++) cin >> grid[i][j];

    sol1();
    sol2();
    sol3();
    sol4();
    sol5();

    for (int tt = 0; tt < 100; tt++) sol6();

    for(i = 0; i < n; i++) {
        for (j = 0; j < n; j++) cout << ans[i][j] << " ";
        cout << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB K = 19
2 Incorrect 3 ms 332 KB K = 613
3 Execution timed out 2052 ms 536 KB Time limit exceeded
4 Runtime error 39 ms 968 KB Execution killed with signal 11
5 Runtime error 34 ms 988 KB Execution killed with signal 11
6 Execution timed out 2062 ms 508 KB Time limit exceeded
7 Partially correct 81 ms 704 KB K = 22314
8 Partially correct 68 ms 724 KB K = 20045
9 Runtime error 33 ms 980 KB Execution killed with signal 11
10 Partially correct 84 ms 716 KB K = 21613