# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
429916 | 2021-06-16T10:27:54 Z | Nicholas_Patrick | Coin Collecting (JOI19_ho_t4) | C++17 | 2 ms | 256 KB |
#include <cstdio> #include <queue> #include <algorithm> using namespace std; int diff(int x, int y){ return x<y?y-x:x-y; } struct point{ int x, y; }; int main(){ int n; scanf("%d", &n); vector<int> top, bot; long long ans=0; for(int i=n*2; i--;){ int x, y; scanf("%d%d", &x, &y); if(y>2){ ans+=y-2; y=2; } if(y<1){ ans+=1-y; y=1; } if(x<1){ ans+=1-x; x=1; } if(x>n){ ans+=x-n; x=n; } if(y==2) top.push_back(x-1); else bot.push_back(x-1); } sort(top.begin(), top.end()); sort(bot.begin(), bot.end()); for(int i=n; i--;){ if(top.empty() or not bot.empty() and top.back()<bot.back()){ ans+=diff(bot.back(), i); bot.pop_back(); if(bot.empty() or not top.empty() and top.back()>=bot.back()){ ans+=diff(top.back(), i); top.pop_back(); }else{ ans+=diff(bot.back(), i); bot.pop_back(); ans++; } }else{ ans+=diff(top.back(), i); top.pop_back(); if(top.empty() or not bot.empty() and bot.back()>=top.back()){ ans+=diff(bot.back(), i); bot.pop_back(); }else{ ans+=diff(top.back(), i); top.pop_back(); ans++; } } } printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 240 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Incorrect | 2 ms | 204 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 240 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Incorrect | 2 ms | 204 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 256 KB | Output is correct |
2 | Correct | 1 ms | 256 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 240 KB | Output is correct |
5 | Correct | 0 ms | 204 KB | Output is correct |
6 | Incorrect | 2 ms | 204 KB | Output isn't correct |
7 | Halted | 0 ms | 0 KB | - |