제출 #651388

#제출 시각아이디문제언어결과실행 시간메모리
651388AlanHandcrafted Gift (IOI20_gift)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> #include "gift.h" using namespace std; int construct(int n, int m, vector<int> a, vector<int> b, vector<int> x) { string s (n, 0); vector<int> d (n+1), ps (n+1); for (int i = 0; i < m; i++) if (x[i] == 1) { d[a[i]]++; d[b[i]+1]--; } bool b = true; for (int i = 0; i < n; i++) { if (!d[i]) b = !b; s[i] = b ? 'R' : 'B'; ps[i] += s[i] == 'B'; if (i) ps[i] += ps[i-1]; } for (int i = 0; i < m; i++) if (x[i] == 2) { int diff = ps[b[i]] - (a[i] ? ps[a[i]] : 0); if (diff == 0 || diff == b[i]-a[i]+1) return 0; } craft(s); return 1; }

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

gift.cpp: In function 'int construct(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
gift.cpp:12:7: error: declaration of 'bool b' shadows a parameter
   12 |  bool b = true;
      |       ^
gift.cpp:5:56: note: 'std::vector<int> b' previously declared here
    5 | int construct(int n, int m, vector<int> a, vector<int> b, vector<int> x) {
      |                                            ~~~~~~~~~~~~^
gift.cpp:20:18: error: invalid types 'bool[int]' for array subscript
   20 |   int diff = ps[b[i]] - (a[i] ? ps[a[i]] : 0);
      |                  ^
gift.cpp:21:29: error: invalid types 'bool[int]' for array subscript
   21 |   if (diff == 0 || diff == b[i]-a[i]+1) return 0;
      |                             ^