Submission #1114904

# Submission time Handle Problem Language Result Execution time Memory
1114904 2024-11-19T18:09:22 Z codexistent Domino (COCI15_domino) C++14
30 / 160
3206 ms 314168 KB
#include <bits/stdc++.h>
using namespace std;
#define MAXN 2005
#define ll long long
#define FOR(i, a, b) for(ll i = a; i <= b; i++)
#define fs first
#define sc second

ll n, k, g[MAXN][MAXN], r, s = 0, m;
vector<pair<ll, pair<pair<ll, ll>, bool>>> d;
bool v[MAXN][MAXN];

void recurse(ll itr = 0, ll i = -1, ll sm = 0){
    if(itr == k){
        r = min(r, s - sm);
        return;
    }

    FOR(i2, i + 1, m - 1){
        if(v[d[i2].sc.fs.fs][d[i2].sc.fs.sc] || v[d[i2].sc.fs.fs + !d[i2].sc.sc][d[i2].sc.fs.sc + d[i2].sc.sc]){
            continue;
        }
        v[d[i2].sc.fs.fs][d[i2].sc.fs.sc] = true;
        v[d[i2].sc.fs.fs + !d[i2].sc.sc][d[i2].sc.fs.sc + d[i2].sc.sc] = true;

        recurse(itr + 1, i2, sm + d[i2].fs);

        v[d[i2].sc.fs.fs][d[i2].sc.fs.sc] = false;
        v[d[i2].sc.fs.fs + !d[i2].sc.sc][d[i2].sc.fs.sc + d[i2].sc.sc] = false;
    }
}

int main(){
    cin >> n >> k;
    FOR(i, 1, n) FOR(j, 1, n) {
        cin >> g[i][j];
        v[i][j] = false;
        s += g[i][j];
    }
    r = s;

    FOR(i, 1, n) FOR(j, 1, n) {
        if(i != n) d.push_back({g[i][j] + g[i + 1][j], {{i, j}, 0}});
        if(j != n) d.push_back({g[i][j] + g[i][j + 1], {{i, j}, 1}});
    }
    sort(begin(d), end(d));
    reverse(begin(d), end(d));

    m = min((k - 1) * 6 + 1, 2 * n * (n - 1));
    recurse();

    cout << r << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 90 ms 31416 KB Output is correct
2 Correct 84 ms 31440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5112 KB Output is correct
2 Incorrect 2 ms 5112 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1895 ms 298424 KB Output is correct
2 Incorrect 1543 ms 298328 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Incorrect 1 ms 2384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1113 ms 291988 KB Output is correct
2 Incorrect 1144 ms 292036 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 426 ms 86940 KB Output is correct
2 Incorrect 429 ms 86712 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1893 ms 298380 KB Output is correct
2 Incorrect 1930 ms 298380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4944 KB Output is correct
2 Incorrect 3 ms 4944 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1920 ms 298420 KB Output is correct
2 Incorrect 1861 ms 298444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 82 ms 7880 KB Output is correct
2 Incorrect 17 ms 7880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1949 ms 298416 KB Output is correct
2 Incorrect 1998 ms 298444 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 871 ms 5324 KB Output is correct
2 Incorrect 98 ms 5324 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1578 ms 86736 KB Output is correct
2 Incorrect 550 ms 90780 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2500 KB Output is correct
2 Correct 21 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3206 ms 298464 KB Output is correct
2 Incorrect 2224 ms 314168 KB Output isn't correct
3 Halted 0 ms 0 KB -