# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892853 | 2023-12-26T05:36:56 Z | vjudge1 | Coin Collecting (JOI19_ho_t4) | C++17 | 1 ms | 600 KB |
#include "bits/stdc++.h" using namespace std; // #pragma comment(linker, "/stack:200000000") // #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using ll = long long; using ld = long double; #define pb push_back #define ff first #define ss second #define sz(x) (ll)(x).size() #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; } ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; } template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); } template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; } const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN; const ll mod = 1e9+7, N = 3e5+5; ll used[N], have[N][3]; void kigash() { ll n; cin>>n; vector<pair<ll, ll>> v; for(ll i=1; i<=2*n; i++) { ll x, y; cin>>x>>y; v.pb({x, y}); } ll ans = 0; while(1) { ll mn = MX, x1 = -1, y1 = -1, x2 = -1, y2 = -1; for(ll i=1; i<=2*n; i++) { if(used[i]) continue; for(ll j=1; j<=n; j++) { for(ll k=1; k<=2; k++) { if(have[j][k]) continue; ll x = v[i-1].ff, y = v[i-1].ss; if(abs(x-j)+abs(y-k)<mn) { mn = abs(x-j)+abs(y-k); x1 = i, x2 = j, y2 = k; } } } } if(mn==MX) break; ans += mn; used[x1] = have[x2][y2] = 1; } cout<<ans<<"\n"; return; } signed main(/*Kigash Amir*/) { // freopen(""); IOIGold2024_InshAllah(); ll tt = 1; // cin>>tt; for(ll i=1; i<=tt; i++) { kigash(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 0 ms | 600 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 0 ms | 600 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Incorrect | 0 ms | 600 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |