Submission #1063909

#TimeUsernameProblemLanguageResultExecution timeMemory
1063909_8_8_Coin Collecting (JOI19_ho_t4)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 12, MOD = (int)1e9 + 7; #define int ll int n; int c[N][2],a[N]; int dist(int x,int y,int x1,int y1) { return abs(x - x1) + abs(y - y1); } ll ans = 0; void test() { cin >> n; for(int i = 1;i <= n + n;i++) { int a,b; cin >> a >> b; int x = 1,y = 1; auto upd = [&](int x1,int y1) { if(dist(x1,y1,a,b) < dist(x,y,a,b)) { x = x1; y = y1; } }; upd(1,2); upd(n,1); upd(n,2); if(a >= 1 && a <= n) { upd(a,1); upd(a,2); } if(b >= 1 && b <= 2) { upd(1,b); upd(n,b); } c[x][y]++; ans += dist(x,y,a,b); } int x =0,y = 0; for(int i = 1;i <= n;i++) { x += c[i][1]; y += c[i][2]; a[i] = c[i][1] + c[i][2]; } // for(int i = 1;i <= n;i++) { // cout << c[i][1] << ' ' << c[i][2] << '\n'; // } ans += abs(x - y) / 2; vector<int> l,r; for(int i = 1;i <= n;i++) { for(int j = 0;j < a[i] - 2;j++) { l.push_back(i); } for(int j = 0;j < 2 - a[i];j++) { r.push_back(i); } } assert((int)l.size() == (int)r.size()); for(int i = 0;i < (int)l.size();i++) { ans += abs(l[i] - r[i]); } cout << ans; } signed main() { ios_base::sync_with_stdio(false);cin.tie(0); int t = 1; // cin >> t; while(t--) { test(); } }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'void test()':
joi2019_ho_t4.cpp:43:20: warning: array subscript 2 is above array bounds of 'll [2]' {aka 'long long int [2]'} [-Warray-bounds]
   43 |         y += c[i][2];
      |              ~~~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...