Submission #99677

#TimeUsernameProblemLanguageResultExecution timeMemory
99677cki86201Coin Collecting (JOI19_ho_t4)C++11
8 / 100
7 ms2176 KiB
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <stack> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_set> #include <bitset> #include <time.h> #include <limits.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) (int)x.size() #define rep(i,n) for(int i=0;i<n;i++) #define all(x) x.begin(),x.end() typedef tuple<int, int, int> t3; int N; pii p[200010]; ll ans; const int B = 100; ll temp[100010][2*B+5]; ll *dp[100010]; void upd(ll &a, ll b) { if(a > b) a = b; } ll dis(pii a, pii b) { return (ll)abs(a.Fi - b.Fi) + abs(a.Se - b.Se); } int main() { scanf("%d", &N); for(int i=1;i<=2*N;i++) { int x, y; scanf("%d%d", &x, &y); if(x < 1) ans += 1 - x, x = 1; if(x > N) ans += x - N, x = N; if(y < 1) ans += 1 - y, y = 1; if(y > 2) ans += y - 2, y = 2; p[i] = pii(x, y); } sort(p+1, p+1+2*N); for(int i=0;i<=N;i++) dp[i] = temp[i] + B + 2; for(int i=0;i<=N;i++) for(int j=-B;j<=B;j++) dp[i][j] = 1e18; dp[0][0] = 0; for(int i=0;i<=N;i++) for(int dj=-B;dj<=B;dj++) { int j = i + dj; if(0 <= j && j <= N); else continue; pii pv = p[i + j + 1]; if(i < N) { upd(dp[i+1][dj-1], dis(pv, pii(i+1, 1)) + dp[i][dj]); } if(j < N) { upd(dp[i][dj+1], dis(pv, pii(j+1, 2)) + dp[i][dj]); } } printf("%lld\n", ans + dp[N][0]); return 0; }

Compilation message (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:43: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:45:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...