답안 #608429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
608429 2022-07-27T07:35:56 Z yanndev 장난감 기차 (IOI17_train) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MX = 5042;

int n;
int deg[MX];
bool vis[MX];
bool vis2[MX];
bool isOk[MX];
bool isAlice[MX];
bool isCharge[MX];
int nxt[MX];
int left = 0;
int right = 0;
vector<int> rgraph[MX];

bool BFS() {
    left = right = 0;
    for (int i = 0; i < n; i++)
        deg[i] = 0;
    for (int i = 0; i < n; i++) {
        for (auto& x: rgraph[i])
            deg[x]++;
        if (isCharge[i] && isOk[i])
            nxt[right++];
        vis[i] = vis2[i] = false;
    }

    //cout << layer << ' ' << (int)nxt.size() << '\n';
    
    while (left < right) {
        auto cur = nxt[left++];
        //cout << "cur is " << cur << '\n';
        //nxt.pop();

        for (auto& x: rgraph[cur]) {
            if (!vis2[x] && ((--deg[x] == 0) || isAlice[x])) {
                vis2[x] = true;
                nxt[right++] = x;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        if (isOk[i] && !vis2[i]) {
            isOk[i] = false;
            return true;
        }
    }

    return false;
}

vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
    n = (int)a.size();

    for (int i = 0; i < (int)u.size(); i++)
        rgraph[v[i]].push_back(u[i]);
    
    for (int i = 0; i < n; i++) {
        isAlice[i] = a[i];
        isCharge[i] = r[i];
        isOk[i] = true;
    }

    while (BFS());

    vector<int> ans (n);
    for (int i = 0; i < n; i++)
        ans[i] = isOk[i];
    return ans;
}

Compilation message

train.cpp: In function 'bool BFS()':
train.cpp:19:5: error: reference to 'left' is ambiguous
   19 |     left = right = 0;
      |     ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
train.cpp:14:5: note:                 'int left'
   14 | int left = 0;
      |     ^~~~
train.cpp:19:12: error: reference to 'right' is ambiguous
   19 |     left = right = 0;
      |            ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
train.cpp:15:5: note:                 'int right'
   15 | int right = 0;
      |     ^~~~~
train.cpp:26:17: error: reference to 'right' is ambiguous
   26 |             nxt[right++];
      |                 ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
train.cpp:15:5: note:                 'int right'
   15 | int right = 0;
      |     ^~~~~
train.cpp:32:12: error: reference to 'left' is ambiguous
   32 |     while (left < right) {
      |            ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
train.cpp:14:5: note:                 'int left'
   14 | int left = 0;
      |     ^~~~
train.cpp:32:19: error: reference to 'right' is ambiguous
   32 |     while (left < right) {
      |                   ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
train.cpp:15:5: note:                 'int right'
   15 | int right = 0;
      |     ^~~~~
train.cpp:33:24: error: reference to 'left' is ambiguous
   33 |         auto cur = nxt[left++];
      |                        ^~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1006:3: note: candidates are: 'std::ios_base& std::left(std::ios_base&)'
 1006 |   left(ios_base& __base)
      |   ^~~~
train.cpp:14:5: note:                 'int left'
   14 | int left = 0;
      |     ^~~~
train.cpp:40:21: error: reference to 'right' is ambiguous
   40 |                 nxt[right++] = x;
      |                     ^~~~~
In file included from /usr/include/c++/10/ios:42,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from train.cpp:1:
/usr/include/c++/10/bits/ios_base.h:1014:3: note: candidates are: 'std::ios_base& std::right(std::ios_base&)'
 1014 |   right(ios_base& __base)
      |   ^~~~~
train.cpp:15:5: note:                 'int right'
   15 | int right = 0;
      |     ^~~~~