Submission #429916

#TimeUsernameProblemLanguageResultExecution timeMemory
429916Nicholas_PatrickCoin Collecting (JOI19_ho_t4)C++17
0 / 100
2 ms256 KiB
#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 (stderr)

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:45:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   45 |   if(top.empty() or not bot.empty() and top.back()<bot.back()){
      |                     ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:48:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   48 |    if(bot.empty() or not top.empty() and top.back()>=bot.back()){
      |                      ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:59:38: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   59 |    if(top.empty() or not bot.empty() and bot.back()>=top.back()){
      |                      ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...