제출 #657864

#제출 시각아이디문제언어결과실행 시간메모리
657864gg123_pe동굴 (IOI13_cave)C++14
컴파일 에러
0 ms0 KiB
#include "cave.h" #include <bits/stdc++.h> using namespace std; #define f(i,a,b) for(int i = a; i < b; i++) /* vector <int> s, d, p; int n; int tryCombination(vector <int> v){ f(i,0,n) if(v[p[i]] != s[p[i]]) return i; return -1; } void answer(vector <int> si, vector <int> di){ f(i,0,n){ if(si[i] != s[i] or di[i] != d[i]){ cout << "WA\n"; return; } } cout << "AC\n"; } */ vector <int> v, S, D, inv; void change(int l, int r){ f(i,l,r+1) if(D[i] == -1) v[i] = 1 - v[i]; } int tri(vector <int> r){ int ans = tryCombination(r); if(ans == -1) ans = n; return ans; } void find(int x){ f(i,0,n) v[i] = 0; f(i,0,x) v[inv[i]] = S[inv[i]]; int l = 0, r = n-1; int val = tri(v); int u; if(val == x){ u = 1; while(l < r){ int m = (l+r)>>1; change(0, m); /* cout << l << " " << r << "\n"; f(i,0,n) cout << v[i] << " "; cout << "\n" << tryCombination(v) << "\n"; */ if(tri(v) != val) r = m; else l = m+1; change(0, m); } } else{ u = 0; while(l < r){ int m = (l+r)>>1; change(0, m); if(tri(v) <= val) r = m; else l = m+1; change(0, m); } } S[l] = u, D[l] = x, inv[x] = l; } void exploreCave(int n) { v.assign(n, 0), S.assign(n, -1), D.assign(n, -1), inv.assign(n, -1); f(i,0,n) find(i); answer(S, D); } /* int main(){ cin >> n; s.resize(n), d.resize(n), p.resize(n); f(i,0,n) cin >> s[i]; f(i,0,n) cin >> d[i], p[d[i]] = i; exploreCave(n); return 0; } */

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

cave.cpp: In function 'int tri(std::vector<int>)':
cave.cpp:35:30: error: cannot convert 'std::vector<int>' to 'int*'
   35 |     int ans = tryCombination(r);
      |                              ^
      |                              |
      |                              std::vector<int>
In file included from cave.cpp:1:
cave.h:8:24: note:   initializing argument 1 of 'int tryCombination(int*)'
    8 | int tryCombination(int S[]);
      |                    ~~~~^~~
cave.cpp:36:25: error: 'n' was not declared in this scope
   36 |     if(ans == -1) ans = n;
      |                         ^
cave.cpp: In function 'void find(int)':
cave.cpp:40:8: error: 'n' was not declared in this scope
   40 |  f(i,0,n) v[i] = 0;
      |        ^
cave.cpp:5:37: note: in definition of macro 'f'
    5 | #define f(i,a,b) for(int i = a; i < b; i++)
      |                                     ^
cave.cpp:43:17: error: 'n' was not declared in this scope
   43 |  int l = 0, r = n-1;
      |                 ^
cave.cpp: In function 'void exploreCave(int)':
cave.cpp:86:12: error: cannot convert 'std::vector<int>' to 'int*'
   86 |     answer(S, D);
      |            ^
      |            |
      |            std::vector<int>
In file included from cave.cpp:1:
cave.h:9:17: note:   initializing argument 1 of 'void answer(int*, int*)'
    9 | void answer(int S[], int D[]);
      |             ~~~~^~~