# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
258918 |
2020-08-06T19:29:58 Z |
Vimmer |
Domino (COCI15_domino) |
C++14 |
|
1447 ms |
52660 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, 5> a5;
//typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
bool mk[2005][2005];
int a[2005][2005], id = 2, idr[2005][2005];
pair <int, int> idrr[2005];
ll sum, ans, dp[2005], pr[2005];
vector <a5> edges;
bool cmp(pair <int, int> x, pair <int, int> y) {return a[x.F][x.S] > a[y.F][y.S];}
vector <pair <int, int> > gr;
set <pair <int, int> > wh, bl;
void add(pair <int, int> t) {if (mk[t.F][t.S]) bl.insert({t.F, t.S}); else wh.insert({t.F, t.S});}
void add_edge(int from, int to, int cost)
{
edges.pb({from, to, cost, 0, 1});
edges.pb({to, from, -cost, 0, 0});
}
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);
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
{
cin >> a[i][j];
sum += ll(a[i][j]);
gr.pb({i, j});
if (!mk[i][j])
{
if (i + 1 != n) mk[i + 1][j] = 1;
if (j + 1 != n) mk[i][j + 1] = 1;
}
}
sort(gr.begin(), gr.end(), cmp);
for (int i = 0; i < min(100, sz(gr)); i++)
{
add(gr[i]);
if (gr[i].F != 0) add({gr[i].F - 1, gr[i].S});
if (gr[i].S != 0) add({gr[i].F, gr[i].S - 1});
if (gr[i].F + 1 != n) add({gr[i].F + 1, gr[i].S});
if (gr[i].S + 1 != n) add({gr[i].F, gr[i].S + 1});
}
for (auto it : wh)
{
idrr[id] = {it.F, it.S};
idr[it.F][it.S] = id++;
add_edge(0, idr[it.F][it.S], 0);
}
for (auto it : bl)
{
idrr[id] = {it.F, it.S};
idr[it.F][it.S] = id++;
add_edge(idr[it.F][it.S], 1, 0);
}
for (auto it : bl)
for (auto itr : wh)
if (abs(itr.F - it.F) + abs(itr.S - it.S) == 1)
add_edge(idr[itr.F][itr.S], idr[it.F][it.S], -(a[itr.F][itr.S] + a[it.F][it.S]));
for (; k > 0; k--)
{
for (int i = 0; i < 2005; i++) dp[i] = 1e18;
dp[0] = 0;
for (int it = 0; it < 10000; it++)
for (int i = 0; i < sz(edges); i++)
{
int to = edges[i][1], from = edges[i][0], cost = edges[i][2], flow = edges[i][3], cap = edges[i][4];
if (flow < cap && dp[from] < 1e18 && dp[from] + cost < dp[to])
{
dp[to] = dp[from] + cost;
pr[to] = i;
}
}
ans += dp[1];
int v = 1;
while (v != 0)
{
int id = pr[v];
edges[id][3]++;
edges[id ^ 1][3]--;
v = edges[id][0];
}
}
cout << sum + ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
7272 KB |
Output is correct |
2 |
Correct |
58 ms |
6504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
58 ms |
1152 KB |
Output is correct |
2 |
Correct |
34 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1328 ms |
52660 KB |
Output is correct |
2 |
Correct |
674 ms |
51616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
640 KB |
Output is correct |
2 |
Correct |
33 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
735 ms |
47048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
352 ms |
19284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1330 ms |
52376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
1148 KB |
Output is correct |
2 |
Correct |
125 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1403 ms |
52508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
189 ms |
1664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
384 KB |
Output is correct |
2 |
Correct |
11 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1392 ms |
52512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
1280 KB |
Output is correct |
2 |
Correct |
176 ms |
1164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
451 ms |
19028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
384 KB |
Output is correct |
2 |
Correct |
21 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1447 ms |
52608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |