제출 #56622

#제출 시각아이디문제언어결과실행 시간메모리
56622leejseoPalembang Bridges (APIO15_bridge)C++98
컴파일 에러
0 ms0 KiB
#include#inclu <bits/stdc++.h> using namespace std; int K, N; void solve1(){ long long ans = 0; vector<int> L; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ L.push_back(u); L.push_back(v); } } sort(L.begin(), L.end()); int M = L.size(); if (M == 0){ printf("%lld\n", ans); return; } long long mid = L[M/2]; for (int i=0; i<M; i++) ans += abs(L[i] - mid); ans += M/2; printf("%lld\n", ans); L.clear(); return; } long long f(vector<int>&X, vector<int>&Y, int s){ vector<int> lo, hi; int N = X.size(); for (int i=0; i<N; i++){ if (X[i] + Y[i] < s){ lo.push_back(X[i]); lo.push_back(Y[i]); } else{ hi.push_back(X[i]); hi.push_back(Y[i]); } } long long ans = 0LL; sort(lo.begin(), lo.end()); sort(hi.begin(), hi.end()); for (int i=0; i<N; i++){ if (X[i] + Y[i] < s) ans += abs(X[i]-lo[lo.size()/2])+abs(Y[i]-lo[lo.size()/2]); else ans += abs(X[i]-hi[hi.size()/2])+abs(Y[i]-hi[hi.size()/2]); } lo.clear(); hi.clear(); return ans; } void solve2(){ long long ans = 0; vector<int> S; vector<int> X; vector<int> Y; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ S.push_back(u+v); X.push_back(u); Y.push_back(v); } } int M = X.size(); if (M == 0){ printf("%lld\n", ans); return; } sort(S.begin(), S.end()); unique(S.begin(), S.end()); int lo = 0, hi = S.size()-1; long long temp = 1LL << 61; if (hi <= 2000){ for (int i=lo; i<=hi; i++){ temp = min(temp, f(X, Y, S[i])); } } else{ while (lo + 20 < hi){ int llh = (lo + lo + hi)/3; int lhh = (lo + hi + hi + 1)/3; long long left = f(X, Y, S[llh]), right = f(X, Y, S[lhh]); if (left < right) hi = lhh - 1; else if (left == right){ lo = llh; hi = lhh; } else lo = llh+1; } for (int i=lo; i<=hi; i++){ temp = min(temp, f(X, Y, S[i])); } } ans += temp; ans += M; printf("%lld\n", ans); return; } int main(void){ scanf("%d%d\n", &K, &N); if (K == 1) solve1(); else solve2(); }

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

bridge.cpp:2:9: error: #include expects "FILENAME" or <FILENAME>
 #include#inclu  <bits/stdc++.h>
         ^
bridge.cpp: In function 'void solve1()':
bridge.cpp:9:2: error: 'vector' was not declared in this scope
  vector<int> L;
  ^~~~~~
bridge.cpp:9:9: error: expected primary-expression before 'int'
  vector<int> L;
         ^~~
bridge.cpp:13:3: error: 'scanf' was not declared in this scope
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ^~~~~
bridge.cpp:14:22: error: 'abs' was not declared in this scope
   if (x == y) ans += abs(u-v);
                      ^~~
bridge.cpp:14:22: note: suggested alternative: 'ans'
   if (x == y) ans += abs(u-v);
                      ^~~
                      ans
bridge.cpp:16:4: error: 'L' was not declared in this scope
    L.push_back(u);
    ^
bridge.cpp:20:7: error: 'L' was not declared in this scope
  sort(L.begin(), L.end());
       ^
bridge.cpp:20:2: error: 'sort' was not declared in this scope
  sort(L.begin(), L.end());
  ^~~~
bridge.cpp:20:2: note: suggested alternative: 'short'
  sort(L.begin(), L.end());
  ^~~~
  short
bridge.cpp:23:3: error: 'printf' was not declared in this scope
   printf("%lld\n", ans);
   ^~~~~~
bridge.cpp:23:3: note: suggested alternative: 'int'
   printf("%lld\n", ans);
   ^~~~~~
   int
bridge.cpp:27:33: error: 'abs' was not declared in this scope
  for (int i=0; i<M; i++) ans += abs(L[i] - mid);
                                 ^~~
bridge.cpp:27:33: note: suggested alternative: 'ans'
  for (int i=0; i<M; i++) ans += abs(L[i] - mid);
                                 ^~~
                                 ans
bridge.cpp:29:2: error: 'printf' was not declared in this scope
  printf("%lld\n", ans);
  ^~~~~~
bridge.cpp:29:2: note: suggested alternative: 'int'
  printf("%lld\n", ans);
  ^~~~~~
  int
bridge.cpp: At global scope:
bridge.cpp:34:13: error: 'vector' was not declared in this scope
 long long f(vector<int>&X, vector<int>&Y, int s){
             ^~~~~~
bridge.cpp:34:20: error: expected primary-expression before 'int'
 long long f(vector<int>&X, vector<int>&Y, int s){
                    ^~~
bridge.cpp:34:28: error: 'vector' was not declared in this scope
 long long f(vector<int>&X, vector<int>&Y, int s){
                            ^~~~~~
bridge.cpp:34:35: error: expected primary-expression before 'int'
 long long f(vector<int>&X, vector<int>&Y, int s){
                                   ^~~
bridge.cpp:34:43: error: expected primary-expression before 'int'
 long long f(vector<int>&X, vector<int>&Y, int s){
                                           ^~~
bridge.cpp:34:48: error: expression list treated as compound expression in initializer [-fpermissive]
 long long f(vector<int>&X, vector<int>&Y, int s){
                                                ^
bridge.cpp: In function 'void solve2()':
bridge.cpp:61:2: error: 'vector' was not declared in this scope
  vector<int> S;
  ^~~~~~
bridge.cpp:61:9: error: expected primary-expression before 'int'
  vector<int> S;
         ^~~
bridge.cpp:62:9: error: expected primary-expression before 'int'
  vector<int> X;
         ^~~
bridge.cpp:63:9: error: expected primary-expression before 'int'
  vector<int> Y;
         ^~~
bridge.cpp:67:3: error: 'scanf' was not declared in this scope
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ^~~~~
bridge.cpp:68:22: error: 'abs' was not declared in this scope
   if (x == y) ans += abs(u-v);
                      ^~~
bridge.cpp:68:22: note: suggested alternative: 'ans'
   if (x == y) ans += abs(u-v);
                      ^~~
                      ans
bridge.cpp:70:4: error: 'S' was not declared in this scope
    S.push_back(u+v);
    ^
bridge.cpp:71:4: error: 'X' was not declared in this scope
    X.push_back(u);
    ^
bridge.cpp:72:4: error: 'Y' was not declared in this scope
    Y.push_back(v);
    ^
bridge.cpp:75:10: error: 'X' was not declared in this scope
  int M = X.size();
          ^
bridge.cpp:77:3: error: 'printf' was not declared in this scope
   printf("%lld\n", ans);
   ^~~~~~
bridge.cpp:77:3: note: suggested alternative: 'int'
   printf("%lld\n", ans);
   ^~~~~~
   int
bridge.cpp:80:7: error: 'S' was not declared in this scope
  sort(S.begin(), S.end());
       ^
bridge.cpp:80:2: error: 'sort' was not declared in this scope
  sort(S.begin(), S.end());
  ^~~~
bridge.cpp:80:2: note: suggested alternative: 'short'
  sort(S.begin(), S.end());
  ^~~~
  short
bridge.cpp:81:2: error: 'unique' was not declared in this scope
  unique(S.begin(), S.end());
  ^~~~~~
bridge.cpp:81:2: note: suggested alternative: 'unix'
  unique(S.begin(), S.end());
  ^~~~~~
  unix
bridge.cpp:86:26: error: 'Y' was not declared in this scope
    temp = min(temp, f(X, Y, S[i]));
                          ^
bridge.cpp:86:33: error: 'f' cannot be used as a function
    temp = min(temp, f(X, Y, S[i]));
                                 ^
bridge.cpp:86:11: error: 'min' was not declared in this scope
    temp = min(temp, f(X, Y, S[i]));
           ^~~
bridge.cpp:93:26: error: 'Y' was not declared in this scope
    long long left = f(X, Y, S[llh]), right = f(X, Y, S[lhh]);
                          ^
bridge.cpp:93:35: error: 'f' cannot be used as a function
    long long left = f(X, Y, S[llh]), right = f(X, Y, S[lhh]);
                                   ^
bridge.cpp:94:15: error: 'right' was not declared in this scope
    if (left < right) hi = lhh - 1;
               ^~~~~
bridge.cpp:102:26: error: 'Y' was not declared in this scope
    temp = min(temp, f(X, Y, S[i]));
                          ^
bridge.cpp:102:33: error: 'f' cannot be used as a function
    temp = min(temp, f(X, Y, S[i]));
                                 ^
bridge.cpp:102:11: error: 'min' was not declared in this scope
    temp = min(temp, f(X, Y, S[i]));
           ^~~
bridge.cpp:107:2: error: 'printf' was not declared in this scope
  printf("%lld\n", ans);
  ^~~~~~
bridge.cpp:107:2: note: suggested alternative: 'int'
  printf("%lld\n", ans);
  ^~~~~~
  int
bridge.cpp: In function 'int main()':
bridge.cpp:111:2: error: 'scanf' was not declared in this scope
  scanf("%d%d\n", &K, &N);
  ^~~~~