제출 #56566

#제출 시각아이디문제언어결과실행 시간메모리
56566leejseoPalembang 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; } void solve2(){ long long ans = 0; vector<int> L; 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{ L.push_back(u); L.push_back(v); X.push_back(u); Y.push_back(v); } } int M = X.size(); if (M == 0){ printf("%lld\n", ans); return; } long long cross = (int) 1e17; long long temp; for (int i=0; i<2*M; i++){ for (int j=0; j<i; j++){ long long b1 = L[i]; long long b2 = L[j]; temp = 0; for (int k=0; k<M; k++){ temp += min(abs(X[k]-b1) + abs(Y[k]-b1), abs(X[k]-b2) + abs(Y[k]-b2)); } cross = min(cross, temp); } } X.clear(); Y.clear(); L.clear(); ans += cross; 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: In function 'void solve2()':
bridge.cpp:36:2: error: 'vector' was not declared in this scope
  vector<int> L;
  ^~~~~~
bridge.cpp:36:9: error: expected primary-expression before 'int'
  vector<int> L;
         ^~~
bridge.cpp:37:9: error: expected primary-expression before 'int'
  vector<int> X;
         ^~~
bridge.cpp:38:9: error: expected primary-expression before 'int'
  vector<int> Y;
         ^~~
bridge.cpp:42:3: error: 'scanf' was not declared in this scope
   scanf("%c %d %c %d\n", &x, &u, &y, &v);  
   ^~~~~
bridge.cpp:43:22: error: 'abs' was not declared in this scope
   if (x == y) ans += abs(u-v);
                      ^~~
bridge.cpp:43:22: note: suggested alternative: 'ans'
   if (x == y) ans += abs(u-v);
                      ^~~
                      ans
bridge.cpp:45:4: error: 'L' was not declared in this scope
    L.push_back(u);
    ^
bridge.cpp:47:4: error: 'X' was not declared in this scope
    X.push_back(u);
    ^
bridge.cpp:48:4: error: 'Y' was not declared in this scope
    Y.push_back(v);
    ^
bridge.cpp:51:10: error: 'X' was not declared in this scope
  int M = X.size();
          ^
bridge.cpp:53:3: error: 'printf' was not declared in this scope
   printf("%lld\n", ans);
   ^~~~~~
bridge.cpp:53:3: note: suggested alternative: 'int'
   printf("%lld\n", ans);
   ^~~~~~
   int
bridge.cpp:60:19: error: 'L' was not declared in this scope
    long long b1 = L[i];
                   ^
bridge.cpp:64:17: error: 'abs' was not declared in this scope
     temp += min(abs(X[k]-b1) + abs(Y[k]-b1), abs(X[k]-b2) + abs(Y[k]-b2));
                 ^~~
bridge.cpp:64:17: note: suggested alternative: 'ans'
     temp += min(abs(X[k]-b1) + abs(Y[k]-b1), abs(X[k]-b2) + abs(Y[k]-b2));
                 ^~~
                 ans
bridge.cpp:64:36: error: 'Y' was not declared in this scope
     temp += min(abs(X[k]-b1) + abs(Y[k]-b1), abs(X[k]-b2) + abs(Y[k]-b2));
                                    ^
bridge.cpp:64:13: error: 'min' was not declared in this scope
     temp += min(abs(X[k]-b1) + abs(Y[k]-b1), abs(X[k]-b2) + abs(Y[k]-b2));
             ^~~
bridge.cpp:66:12: error: 'min' was not declared in this scope
    cross = min(cross, temp);
            ^~~
bridge.cpp:70:2: error: 'Y' was not declared in this scope
  Y.clear();
  ^
bridge.cpp:71:2: error: 'L' was not declared in this scope
  L.clear();
  ^
bridge.cpp:74:2: error: 'printf' was not declared in this scope
  printf("%lld\n", ans);
  ^~~~~~
bridge.cpp:74:2: note: suggested alternative: 'int'
  printf("%lld\n", ans);
  ^~~~~~
  int
bridge.cpp: In function 'int main()':
bridge.cpp:78:2: error: 'scanf' was not declared in this scope
  scanf("%d%d\n", &K, &N);
  ^~~~~