# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
254048 |
2020-07-29T09:26:00 Z |
Vimmer |
Domino (COCI15_domino) |
C++14 |
|
4000 ms |
147676 KB |
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 100050
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 5> a5;
//typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int ans = 0;
ll sum;
int n, k, a[2001][2001], mk[2001][2001], mx, it, t = 7 * 1e8;
vector <pair <int, pair <int, pair <int, int> > > > vr;
inline void dfs(int v, int &kol)
{
if (v == k) {ans = max(ans, kol); return;}
for (int i = 0; i < min(mx, sz(vr)); i++)
{
it++;
if (it == t) {cout << sum - ll(ans) << endl; exit(0);}
int x = vr[i].S.S.F, y = vr[i].S.S.S;
int nkol = kol;
if (mk[x][y] == 0) nkol += a[x][y];
if (vr[i].S.F == 0 && !mk[x - 1][y]) nkol += a[x - 1][y];
if (vr[i].S.F == 1 && !mk[x][y - 1]) nkol += a[x][y - 1];
mk[x][y]++;
if (vr[i].S.F == 0) mk[x - 1][y]++; else mk[x][y - 1]++;
dfs(v + 1, nkol);
mk[x][y]--;
if (vr[i].S.F == 0) mk[x - 1][y]--; else mk[x][y - 1]--;
}
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
if (k <= 5) mx = 30;
else if (k == 6) mx = 24;
else if (k == 7) mx = 13;
else mx = 10;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {cin >> a[i][j]; sum += ll(a[i][j]);}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
if (i != 0) vr.pb({a[i][j] + a[i - 1][j], {0, {i, j}}});
if (j != 0) vr.pb({a[i][j] + a[i][j - 1], {1, {i, j}}});
}
sort(vr.begin(), vr.end());
reverse(vr.begin(), vr.end());
int nkol = 0;
dfs(0, nkol);
cout << sum - ll(ans) << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
11624 KB |
Output is correct |
2 |
Correct |
98 ms |
11624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
896 KB |
Output is correct |
2 |
Correct |
1 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1894 ms |
147416 KB |
Output is correct |
2 |
Correct |
1317 ms |
147540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1043 ms |
143704 KB |
Output is correct |
2 |
Correct |
906 ms |
143576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
464 ms |
41184 KB |
Output is correct |
2 |
Correct |
346 ms |
41168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2638 ms |
147416 KB |
Output is correct |
2 |
Correct |
2069 ms |
147572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3197 ms |
896 KB |
Output is correct |
2 |
Incorrect |
3426 ms |
844 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4104 ms |
147416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1912 ms |
1408 KB |
Output is correct |
2 |
Incorrect |
1937 ms |
1408 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1936 ms |
416 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3791 ms |
147676 KB |
Output is correct |
2 |
Incorrect |
3327 ms |
147540 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3253 ms |
1040 KB |
Output is correct |
2 |
Incorrect |
3218 ms |
1024 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3714 ms |
41188 KB |
Output is correct |
2 |
Incorrect |
3475 ms |
41168 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3268 ms |
432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4094 ms |
147576 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |