제출 #102294

#제출 시각아이디문제언어결과실행 시간메모리
102294Nicholas_PatrickPalembang Bridges (APIO15_bridge)C++17
22 / 100
70 ms2048 KiB
#include <bits/stdc++.h> using namespace std; int k, n; vector <int> h, w, hw; int movementI, movementJ; long long check(int i, int j){ if(i>=n<<1||j>=n<<1||i<0||j<0)return 200000000000000; long long tot=0; movementI=0, movementJ=0; int throughI, throughJ; for(int k = 0;k < n;k ++){ throughI=abs(h[k]-hw[i])+abs(w[k]-hw[i]); throughJ=abs(h[k]-hw[j])+abs(w[k]-hw[j]); if(throughI<throughJ){ if(hw[i]<h[k]) movementI++; if(hw[i]>w[k]) movementI--; tot+=throughI; }else{ if(hw[j]<h[k]) movementJ++; if(hw[j]>w[k]) movementJ--; tot+=throughJ; } } return tot; } int main(){ scanf("%d %d", &k, &n); bool cross;int s, t; long long tot1=0; char c; while(n--){ while(true){ c=getchar(); if(c=='A'){ cross=false; break; }else if(c=='B'){ cross=true; break; } } scanf("%d", &s); while(true){ c=getchar(); if(c=='A'){ break; }else if(c=='B'){ cross^=true; break; } } scanf("%d", &t); if(cross){ if(s>t) swap(s, t); h.push_back(s); w.push_back(t); hw.push_back(s); hw.push_back(t); tot1++; }else{ tot1+=abs(t-s); } } n=h.size(); if(k==1){ sort(hw.begin(), hw.end()); n=hw.size(); long long tot2=0; k=n>>1; for(int i = 0;i < n;i ++) tot2+=abs(hw[k]-hw[i]); printf("%lld\n", tot1+tot2); }else if(k==2){ long long tot2=200000000000000; long long curtot; for(int i = 0;i < n<<1;i ++){ for(int j = 0;j < i;j ++){ curtot=check(i, j); tot2=min(tot2, curtot); } } printf("%lld\n", tot1+tot2); } return 0; } /* 2 5 B 0 A 4 B 1 B 3 A 5 B 7 B 2 A 6 B 1 A 7 */

컴파일 시 표준 에러 (stderr) 메시지

bridge.cpp: In function 'int main()':
bridge.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &k, &n);
  ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &s);
   ~~~~~^~~~~~~~~~
bridge.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &t);
   ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...