Submission #153321

#TimeUsernameProblemLanguageResultExecution timeMemory
153321mhy908Coin Collecting (JOI19_ho_t4)C++14
100 / 100
78 ms4988 KiB
#include <bits/stdc++.h> #define F first #define S second #define pb push_back #define llinf 8987654321987654321 #define inf 1987654321 using namespace std; typedef long long LL; typedef pair<int, int> pii; typedef pair<LL, LL> pll; LL ans; int cnt[100010][3], temp1, temp2; int n; int main() { scanf("%d", &n); for(int i=1; i<=2*n; i++){ LL x, y; scanf("%lld %lld", &x, &y); if(x<1)ans+=1-x, x=1; if(x>n)ans+=x-(LL)n, x=(LL)n; if(y<1)ans+=1-y, y=1; if(y>2)ans+=y-2, y=2; cnt[(int)x][(int)y]++; } for(int i=1; i<=n; i++){ temp1+=cnt[i][1]-1; temp2+=cnt[i][2]-1; if(temp1>0&&temp2<0){ int t=min(temp1, -temp2); ans+=(LL)t; temp1-=t; temp2+=t; } if(temp1<0&&temp2>0){ int t=min(-temp1, +temp2); ans+=(LL)t; temp1+=t; temp2-=t; } ans+=llabs((LL)temp1)+llabs((LL)temp2); } printf("%lld", ans); }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:19:14: 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...