# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
709182 |
2023-03-13T07:21:13 Z |
vjudge1 |
Domino (COCI15_domino) |
C++17 |
|
275 ms |
31740 KB |
#include <bits/stdc++.h>
using namespace std;
// #pragma comment(linker, "/stack:2000000000")
// #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
#define precise(a) cout<<fixed<<setprecision(a)
#define sz size()
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
// t1
const ll mod = ll(1e9)+7; //(b + (a%b)) % b (to mod -1%(10^9+7) correctly in c++ its -1 but its suppose to be 10^9+6
const ll MOD = 998244353; // (a%mod)*(binpow(b,mod-2,mod) = (a/b)%mod
const ll N = ll(1e6)+10;
const ll K = 17;
const ll inf = 4e18;
const ld eps = 1e-15L;
// const ll B = 316;
// const ld pie = acos(-1.0);
ll lcm(ll a, ll b){ return (a / __gcd(a,b))*b; }
ll binpow(ll a, ll b, ll m){ ll res=1;a%=m; while(b>0){ if(b&1)res=(res*a)%m; a=(a*a)%m; b/=2; } return res%m;}
void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
void precalc() {
}
bool took[2005][2005];
set<pair<ll, pair<pair<ll, ll> , pair<ll, ll> > > >st;
ll a[2005][2005];
ll n, k;
void Baizho()
{
ll lim = 200;
cin>>n>>k;
for(ll i=1; i<=n; i++) {
for(ll j=1; j<=n; j++) {
cin>>a[i][j];
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(i+1<=n) {
if(st.sz<lim) st.insert({a[i][j] + a[i+1][j], {{i, j}, {i+1, j}}});
else {
if((*st.begin()).ff<a[i][j] + a[i+1][j]) {
st.insert({a[i][j] + a[i+1][j], {{i, j}, {i+1, j}}});
st.erase(st.begin());
}
}
}
if(j+1<=n) {
if(st.sz<lim) st.insert({a[i][j] + a[i][j+1], {{i, j}, {i, j+1}}});
else {
if((*st.begin()).ff<a[i][j] + a[i][j+1]) {
st.insert({a[i][j] + a[i][j+1], {{i, j}, {i, j+1}}});
st.erase(st.begin());
}
}
}
}
}
while(k--) {
auto get = *st.rbegin();
int x1 = get.ss.ff.ff, y1 = get.ss.ff.ss;
int x2 = get.ss.ss.ff, y2 = get.ss.ss.ss;
st.erase(get);
if(took[x1][y1] || took[x2][y2]) {
k++;
continue;
}
took[x1][y1] = took[x2][y2] = 1;
if(y1==y2) {
// down domino
if(x1-1<1 || x2+1>n || took[x1-1][y1] || took[x2+1][y2]) continue;
st.insert({a[x1-1][y1] + a[x2+1][y2], {{x1-1, y1}, {x2+1, y2}} });
}
if(x1==x2) {
if(y1-1<1 || y2+1>n || took[x1][y1-1] || took[x2][y2+1]) continue;
st.insert({a[x1][y1-1] + a[x2][y2+1], {{x1, y1-1}, {x2, y2+1}} });
}
}
ll ans = 0;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(took[i][j]) continue;
ans+=a[i][j];
}
}
cout<<ans;
}
int main() {
// Freopen("div7");
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
precalc();
int ttt = 1;
// cin>>ttt;
for(int i=1; i<=ttt; i++) {Baizho(); }
}
Compilation message
domino.cpp: In function 'void Baizho()':
domino.cpp:57:13: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > > >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
57 | if(st.sz<lim) st.insert({a[i][j] + a[i+1][j], {{i, j}, {i+1, j}}});
| ~~~~~^~~~
domino.cpp:66:13: warning: comparison of integer expressions of different signedness: 'std::set<std::pair<long long int, std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> > > >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
66 | if(st.sz<lim) st.insert({a[i][j] + a[i][j+1], {{i, j}, {i, j+1}}});
| ~~~~~^~~~
domino.cpp: In function 'void Freopen(std::string)':
domino.cpp:34:34: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
domino.cpp:34:76: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | void Freopen(string Key){ freopen((Key+".in").c_str(), "r", stdin); freopen((Key+".out").c_str(), "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4308 KB |
Output is correct |
2 |
Correct |
17 ms |
4208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
273 ms |
31720 KB |
Output is correct |
2 |
Correct |
234 ms |
31692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
143 ms |
23868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
12184 KB |
Output is correct |
2 |
Correct |
64 ms |
12076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
242 ms |
31720 KB |
Output is correct |
2 |
Correct |
203 ms |
31692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
275 ms |
31724 KB |
Output is correct |
2 |
Correct |
243 ms |
31672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
245 ms |
31664 KB |
Output is correct |
2 |
Correct |
252 ms |
31688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
12112 KB |
Output is correct |
2 |
Correct |
61 ms |
12128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
241 ms |
31724 KB |
Output is correct |
2 |
Correct |
237 ms |
31740 KB |
Output is correct |