제출 #1179553

#제출 시각아이디문제언어결과실행 시간메모리
1179553MongHwaCoin Collecting (JOI19_ho_t4)C++20
37 / 100
49 ms11692 KiB
#pragma GCC optimize ("Ofast") #pragma GCC optimize ("unroll-loops") #include <iostream> #include <vector> #include <algorithm> #include <cstring> using namespace std; #define ll long long #define INF 1e17 #define X first #define Y second int n; ll dp[1005][1005]; vector<pair<ll, ll>> coin; ll go(int u, int d) { if(u == n && d == n) return 0; ll& ret = dp[u][d]; if(ret != -1) return ret; ret = INF; if(u < n) ret = min(ret, go(u+1, d)+abs(u+1-coin[u+d].X)+abs(2-coin[u+d].Y)); if(d < n) ret = min(ret, go(u, d+1)+abs(d+1-coin[u+d].X)+abs(1-coin[u+d].Y)); return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < 2*n; i++) { int x, y; cin >> x >> y; coin.push_back({x, y}); } sort(coin.begin(), coin.end()); memset(dp, -1, sizeof(dp)); cout << go(0, 0) << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...