제출 #779267

#제출 시각아이디문제언어결과실행 시간메모리
779267anhphantBitaro’s Party (JOI18_bitaro)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; void pre_setting() { srand(time(NULL)); ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); if (fopen("birato.inp")) { freopen("birato.inp", "r", stdin); freopen("birato.out", "w", stdout); } #endif // ONLINE_JUDGE } namespace subtask2 { int N, M, Q, is_visited[100007], longest_path[100007], T, Y, C[100007]; vector<int> GR[100007], invGR[100007]; vector<int> topo_order; void init() { cin >> N >> M >> Q; for(int i = 1, s, e; i <= M; i++) { cin >> s >> e; GR[s].push_back(e); invGR[e].push_back(s); } } void topo_dfs(int u) { is_visited[u] = 1; for(int v : GR[u]) { if (!is_visited[v]) topo_dfs(v); } topo_order.push_back(u); } void topo_find() { for(int i = 1; i <= N; i++) if (!is_visited[i]) topo_dfs(i); reverse(topo_order.begin(), topo_order.end()); //for(int u : topo_order) cerr << u << " "; cerr << endl; } void solve() { init(); topo_find(); while(Q--) { //cerr << "START CASE : " << endl; cin >> T >> Y; for(int i = 1; i <= Y; i++) cin >> C[i]; for(int i = 0; i <= N; i++) longest_path[i] = -1e9; longest_path[T] = 0; for(int i = N - 1; i >= 0; i--) { int u = topo_order[i]; if (longest_path[u] == -1e9) continue; for(int v : invGR[u]) { longest_path[v] = max(longest_path[v], longest_path[u] + 1); } } sort(C + 1, C + 1 + Y); int ans = -1, idxC = 1; for(int i = 1; i <= N; i++) { if (idxC <= Y && C[idxC] == i) { idxC++; } else { ans = max(ans, longest_path[i]); //cerr << i << " " << longest_path[i] << endl; } } cout << ans << endl; } } } namespace subtask3 { int N, M, Q, is_visited[100007], longest_path[100007], T, Y, C[100007]; vector<int> GR[100007], invGR[100007]; vector<int> topo_order; vector<pair<int, int>> vlist[100007]; const int B = 3; void init() { cin >> N >> M >> Q; for(int i = 1, s, e; i <= M; i++) { cin >> s >> e; GR[s].push_back(e); invGR[e].push_back(s); } } bool added[100007]; void vlist_construct() { for(int i = 1; i <= N; i++) vlist[i].push_back({i, 0}); for(int u = 1; u <= N; u++) { //cerr << u << endl; for(int v : GR[u]) { vector<pair<int, int>> tmp; int pl = 0, pr = 0; while(pl < vlist[u].size() || pr < vlist[v].size()) { //cerr << pl << " " << pr << endl; if (pl < vlist[u].size() && vlist[u][pl].second + 1 > vlist[v][pr].second) { if (!added[vlist[u][pl].first]) tmp.push_back({vlist[u][pl].first, vlist[u][pl].second + 1}); added[vlist[u][pl].first] = 1; pl++; } else { if (!added[vlist[v][pr].first]) tmp.push_back(vlist[v][pr]); added[vlist[v][pr].first] = 1; pr++; } if (tmp.size() - 2 == B) break; } vlist[v] = tmp; for(auto [zzz, k] : vlist[v]) added[zzz] = 0; } } } void solve() { init(); vlist_construct(); for(int i = 1; i <= N; i++) { sort(vlist[i].begin(), vlist[i].end(), [] (pair<int, int>& x1, pair<int, int>& x2) { return x1.second > x2.second; }); //cerr << "i = " << i << endl; //for(auto [tt, v] : vlist[i]) cerr << tt << " : " << v << endl; //cerr << endl; } fill(is_visited + 1, is_visited + 1 + N, 1); while(Q--) { //cerr << "START CASE" << endl; cin >> T >> Y; for(int i = 1; i <= Y; i++) { cin >> C[i]; is_visited[C[i]] = 0; } //cerr << T << endl; sort(C + 1, C + 1 + Y); if (Y >= B) { //cerr << "case 1" << endl; for(int i = 1; i <= T; i++) longest_path[i] = -1e9; for(int i = 1; i <= T; i++) { //cerr << "init : " << i << " " << longest_path[i] << endl; if (is_visited[i]) longest_path[i] = max(longest_path[i], 0); if (longest_path[i] == -1e9) continue; //cerr << i << " " << longest_path[i] << endl; for(int v : GR[i]) { longest_path[v] = max(longest_path[v], longest_path[i] + 1); //cerr << "v : " << v << " " << longest_path[v] << endl; } } cout << (longest_path[T] < 0? -1 : longest_path[T]) << endl; } else { //cerr << "case 2" << endl; for(auto [u, d] : vlist[T]) { //cerr << u << " " << d << endl; if (is_visited[u]) { cout << d << endl; goto GT; } } cout << -1 << endl; GT: int hope = -1; } for(int i = 1; i <= Y; i++) is_visited[C[i]] = 1; } } } int main() { pre_setting(); subtask3 :: solve(); }

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

bitaro.cpp:13:6: error: #endif without #if
   13 |     #endif // ONLINE_JUDGE
      |      ^~~~~
bitaro.cpp: In function 'void pre_setting()':
bitaro.cpp:9:27: error: too few arguments to function 'FILE* fopen(const char*, const char*)'
    9 |     if (fopen("birato.inp")) {
      |                           ^
In file included from /usr/include/c++/10/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:46,
                 from bitaro.cpp:1:
/usr/include/stdio.h:246:14: note: declared here
  246 | extern FILE *fopen (const char *__restrict __filename,
      |              ^~~~~
bitaro.cpp: In function 'void subtask3::vlist_construct()':
bitaro.cpp:109:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 while(pl < vlist[u].size() || pr < vlist[v].size()) {
      |                       ~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:109:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |                 while(pl < vlist[u].size() || pr < vlist[v].size()) {
      |                                               ~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:111:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |                     if (pl < vlist[u].size() && vlist[u][pl].second + 1 > vlist[v][pr].second) {
      |                         ~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:127:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  127 |                 for(auto [zzz, k] : vlist[v]) added[zzz] = 0;
      |                          ^
bitaro.cpp: In function 'void subtask3::solve()':
bitaro.cpp:177:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  177 |                 for(auto [u, d] : vlist[T]) {
      |                          ^
bitaro.cpp:187:21: warning: unused variable 'hope' [-Wunused-variable]
  187 |                 int hope = -1;
      |                     ^~~~