제출 #466284

#제출 시각아이디문제언어결과실행 시간메모리
466284flappybird즐거운 행로 (APIO20_fun)C++14
컴파일 에러
0 ms0 KiB
#include "fun.h" #include <bits/stdc++.h> #include <cassert> #define e(v) ( ( (v).empty() ) ? (pair<int, int>(-1, -1) ) : ( (v)[(v).size()-1] ) ) using namespace std; typedef int ll; vector<int> createFunTour(int N, int Q) { if (N == 2) { vector<ll> v; v.push_back(0); v.push_back(1); return v; } vector<ll> res; ll i; for (i = 0; i < N; i++) res.push_back(attractionsBehind(0, i)); ll c = 0; ll mn = 1010101010; for (i = 0; i < N; i++) { if (res[i] >= (N + 1) / 2) { if (mn > res[i]) mn = res[i], c = i; } } vector<pair<ll, ll>> dis; vector<vector<pair<ll, ll>>> subtree; subtree.resize(3); ll num; for (i = 0; i < N; i++) { if (i == c) continue; dis.push_back({ hoursRequired(i, c), i }); } sort(dis.begin(), dis.end()); num = 1; subtree[0].push_back(dis[0]); for (i = 1; i < dis.size(); i++) { ll j; for (j = 0; j < num; j++) { if (j == 2) break; if (hoursRequired(dis[i].second, subtree[j][0].second) != dis[i].first + subtree[j][0].first) break; } if (j == num) num++; subtree[j].push_back(dis[i]); } vector<ll> ans; if (num == 2) { ll r = N; ll a; if (subtree[0].size() < subtree[1].size()) a = 1; else a = 0; while (r != 1) { ans.push_back(e(subtree[a]).second); subtree[a].pop_back(); a = !a; r--; } ans.push_back(c); } else { ll r = N; ll a; if (e(subtree[0]).first > e(subtree[1]).first) swap(subtree[0], subtree[1]); if (e(subtree[1]).first > e(subtree[2]).first) swap(subtree[1], subtree[2]); if (e(subtree[0]).first == e(subtree[1]).first && subtree[0].size() > subtree[1].size()) swap(subtree[0], subtree[1]); if (e(subtree[1]).first == e(subtree[2]).first && subtree[1].size() > subtree[2].size()) swap(subtree[1], subtree[2]); a = 2; while (r != 1) { ans.push_back(subtree[a][subtree[a].size() - 1].second); subtree[a].pop_back(); ll b, c; b = a + 1; c = a + 2; b %= 3; c %= 3; if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) { ll mx = ma if (subtree[0].size() < subtree[1].size()) a = 1; else a = 0; while (r != 1) { ans.push_back(e(subtree[a]).second); subtree[a].pop_back(); a = !a; r--; } ans.push_back(c); } else { ll r = N; ll a; if (e(subtree[0]).first > e(subtree[1]).first) swap(subtree[0], subtree[1]); if (e(subtree[1]).first > e(subtree[2]).first) swap(subtree[1], subtree[2]); if (e(subtree[0]).first == e(subtree[1]).first && subtree[0].size() > subtree[1].size()) swap(subtree[0], subtree[1]); if (e(subtree[1]).first == e(subtree[2]).first && subtree[1].size() > subtree[2].size()) swap(subtree[1], subtree[2]); a = 2; while (r != 1) { ans.push_back(subtree[a][subtree[a].size() - 1].second); subtree[a].pop_back(); ll b, c; b = a + 1; c = a + 2; b %= 3; c %= 3; if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) { ll mx = max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }); ll na; if (mx == subtree[0].size()) na = 0; if (mx == subtree[1].size()) na = 1; if (mx == subtree[2].size()) na = 2; if (na == a) { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else if (subtree[0].size() < subtree[1].size()) a = 1; else a = 0; while (r != 1) { ans.push_back(e(subtree[a]).second); subtree[a].pop_back(); a = !a; r--; } ans.push_back(c); } else { ll r = N; ll a; if (e(subtree[0]).first > e(subtree[1]).first) swap(subtree[0], subtree[1]); if (e(subtree[1]).first > e(subtree[2]).first) swap(subtree[1], subtree[2]); if (e(subtree[0]).first == e(subtree[1]).first && subtree[0].size() > subtree[1].size()) swap(subtree[0], subtree[1]); if (e(subtree[1]).first == e(subtree[2]).first && subtree[1].size() > subtree[2].size()) swap(subtree[1], subtree[2]); a = 2; while (r != 1) { ans.push_back(subtree[a][subtree[a].size() - 1].second); subtree[a].pop_back(); ll b, c; b = a + 1; c = a + 2; b %= 3; c %= 3; if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) { ll mx = max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }); ll na; if (mx == subtree[0].size()) na = 0; if (mx == subtree[1].size()) na = 1; if (mx == subtree[2].size()) na = 2; if (na == a) { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else a = b; } else a = na; } else { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else a = b; } r--; } ans.push_back(c); }a = b; } else a = na; } else { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else a = b; } r--; } ans.push_back(c); }x({ subtree[0].size(), subtree[1].size(), subtree[2].size() }); ll na; if (mx == subtree[0].size()) na = 0; if (mx == subtree[1].size()) na = 1; if (mx == subtree[2].size()) na = 2; if (na == a) { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else a = b; } else a = na; } else { if (e(subtree[b]).first < e(subtree[c]).first) a = c; else if (e(subtree[b]).first == e(subtree[c]).first && (subtree[b].size() < subtree[c].size())) a = c; else a = b; } r--; } ans.push_back(c); } return ans; }

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

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:38:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for (i = 1; i < dis.size(); i++) {
      |              ~~^~~~~~~~~~~~
fun.cpp:77:73: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'll' {aka 'int'} [-Wsign-compare]
   77 |    if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
fun.cpp:78:13: error: 'ma' was not declared in this scope; did you mean 'mx'?
   78 |     ll mx = ma  if (subtree[0].size() < subtree[1].size()) a = 1;
      |             ^~
      |             mx
fun.cpp:78:8: warning: unused variable 'mx' [-Wunused-variable]
   78 |     ll mx = ma  if (subtree[0].size() < subtree[1].size()) a = 1;
      |        ^~
fun.cpp:79:3: error: expected '}' before 'else'
   79 |   else a = 0;
      |   ^~~~
fun.cpp:77:81: note: to match this '{'
   77 |    if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) {
      |                                                                                 ^
fun.cpp:88:2: error: 'else' without a previous 'if'
   88 |  else {
      |  ^~~~
fun.cpp:104:73: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'll' {aka 'int'} [-Wsign-compare]
  104 |    if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
fun.cpp:107:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |     if (mx == subtree[0].size()) na = 0;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:108:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     if (mx == subtree[1].size()) na = 1;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:109:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     if (mx == subtree[2].size()) na = 2;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:139:73: warning: comparison of integer expressions of different signedness: 'long unsigned int' and 'll' {aka 'int'} [-Wsign-compare]
  139 |    if (max({ subtree[0].size(), subtree[1].size(), subtree[2].size() }) >= r/2) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
fun.cpp:142:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  142 |     if (mx == subtree[0].size()) na = 0;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:143:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |     if (mx == subtree[1].size()) na = 1;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:144:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  144 |     if (mx == subtree[2].size()) na = 2;
      |         ~~~^~~~~~~~~~~~~~~~~~~~
fun.cpp:162:14: error: 'na' was not declared in this scope; did you mean 'a'?
  162 |     else a = na;
      |              ^~
      |              a
fun.cpp:164:4: error: 'else' without a previous 'if'
  164 |    else {
      |    ^~~~
fun.cpp:165:19: error: 'b' was not declared in this scope
  165 |     if (e(subtree[b]).first < e(subtree[c]).first) a = c;
      |                   ^
fun.cpp:5:19: note: in definition of macro 'e'
    5 | #define e(v) ( ( (v).empty() ) ? (pair<int, int>(-1, -1) ) : ( (v)[(v).size()-1] ) )
      |                   ^
fun.cpp:172:3: error: 'x' was not declared in this scope
  172 |  }x({ subtree[0].size(), subtree[1].size(), subtree[2].size() });
      |   ^
fun.cpp:174:9: error: 'mx' was not declared in this scope; did you mean 'mn'?
  174 |     if (mx == subtree[0].size()) na = 0;
      |         ^~
      |         mn
fun.cpp:175:9: error: 'mx' was not declared in this scope; did you mean 'mn'?
  175 |     if (mx == subtree[1].size()) na = 1;
      |         ^~
      |         mn
fun.cpp:176:9: error: 'mx' was not declared in this scope; did you mean 'mn'?
  176 |     if (mx == subtree[2].size()) na = 2;
      |         ^~
      |         mn
fun.cpp:177:15: error: 'a' was not declared in this scope; did you mean 'na'?
  177 |     if (na == a) {
      |               ^
      |               na
fun.cpp:178:20: error: 'b' was not declared in this scope
  178 |      if (e(subtree[b]).first < e(subtree[c]).first) a = c;
      |                    ^
fun.cpp:5:19: note: in definition of macro 'e'
    5 | #define e(v) ( ( (v).empty() ) ? (pair<int, int>(-1, -1) ) : ( (v)[(v).size()-1] ) )
      |                   ^
fun.cpp: At global scope:
fun.cpp:184:4: error: expected unqualified-id before 'else'
  184 |    else {
      |    ^~~~
fun.cpp:189:4: error: 'r' does not name a type
  189 |    r--;
      |    ^
fun.cpp:190:3: error: expected declaration before '}' token
  190 |   }
      |   ^
fun.cpp:191:3: error: 'ans' does not name a type; did you mean 'abs'?
  191 |   ans.push_back(c);
      |   ^~~
      |   abs
fun.cpp:192:2: error: expected declaration before '}' token
  192 |  }
      |  ^
fun.cpp:193:2: error: expected unqualified-id before 'return'
  193 |  return ans;
      |  ^~~~~~
fun.cpp:194:1: error: expected declaration before '}' token
  194 | }
      | ^
fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:17:13: warning: control reaches end of non-void function [-Wreturn-type]
   17 |  vector<ll> res;
      |             ^~~