Submission #171314

#TimeUsernameProblemLanguageResultExecution timeMemory
171314dennisstarCoin Collecting (JOI19_ho_t4)C++11
100 / 100
79 ms4960 KiB
#include <bits/stdc++.h> #define fi first #define se second #define ryan bear #define now mem[co][r][g][y] #define all(V) ((V).begin()), ((V).end()) using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef long double ld; typedef vector<int> vim; typedef vector<ll> vlm; int N; int cnt[100010][2]; int main() { scanf("%d", &N); ll x, y; ll ans=0; for (int i=0; i<2*N; i++) { scanf("%lld %lld", &x, &y); if (x<1) { ans+=1ll-x; x=1; } else if (x>N) { ans+=x-N; x=N; } if (y>2) { ans+=y-2ll; y=2; } else if (y<1) { ans+=1-y; y=1; } cnt[x][y-1]++; } int c[2]; c[0]=c[1]=0; for (int i=1; i<=N; i++) { c[0]+=cnt[i][0]-1, c[1]+=cnt[i][1]-1; if ((ll)c[0]*c[1]<0) { int im=min(abs(c[0]), abs(c[1])); ans+=(ll)im; c[0]=(abs(c[0])-im)*(c[0]/abs(c[0])); c[1]=(abs(c[1])-im)*(c[1]/abs(c[1])); } ans+=abs(c[0])+abs(c[1]); } printf("%lld\n", ans); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...