Submission #585080

#TimeUsernameProblemLanguageResultExecution timeMemory
585080MazaalaiFriend (IOI14_friend)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "friend.h" #define LINE "------------\n" #define ALL(x) x.begin(),x.end() #define LLA(x) x.rbegin(),x.rend() #define pb push_back using namespace std; using PII = pair <int, int>; using ll = long long; // Find out best sample /* 0 for IAmYourFriend, 1 for MyFriendsAreYourFriends, 2 for WeAreYourFriends. */ const int N = 1e3 + 5; bool isFriend[N][N]; vector <int> paths[N] int dp[N][2], nums[N]; void IAmYourFriend(int x, int y) { if (x > y) swap(x, y); paths[x].pb(y); isFriend[x][y] = isFriend[y][x] = 1; } void MyFriendsAreYourFriends(int x, int y) { for (int i = 0; i < N; i++) if (isFriend[y][i]) IAmYourFriend(el, x); } void WeAreYourFriends(int x, int y) { MyFriendsAreYourFriends(x, y); IAmYourFriend(x, y); } int solve(int pos, int state) { int& res = dp[pos][state]; if (res != -1) return res; res = state * nums[pos]; for (auto el : paths[pos]) { if (state) res += solve(pos, state^1); else res += max(solve(el, state), solve(el, state^1)); } return res; } int findSample(int n, int _nums[], int host[], int type[]){ int ans = 0; for (int i = 0; i < n; i++) nums[i] = _nums[i]; if (n <= 10) { for (int i = 1; i < n; i++) { if (type[i] == 0) IAmYourFriend(i, host[i]); else if (type[i] == 1) MyFriendsAreYourFriends(i, host[i]); else WeAreYourFriends(i, host[i]); } for (int i = 0; i < (1<<n); i++) { vector <int> ids; for (int j = 0; j < n; j++) { if (i & (1<<j)) ids.pb(j); } bool no = 0; for (auto el : ids) for (auto el1 : ids) { no |= isFriend[el][el1]; } if (no) continue; int sum = 0; for (auto el : ids) { // cout << el <<" "; sum += nums[el]; } // cout << ": " << sum << '\n'; ans = max(ans, sum); } } else if (type[1] == 0) { for (int i = 1; i < n; i++) IAmYourFriend(i, host[i]); memset(dp, -1, sizeof(dp)); ans = max( solve(1, 0); solve(1, 1); ); } else if (type[1] == 1) { // cout << "B\n"; for (int i = 0; i < n; i++) ans += nums[i]; } else if (type[1] == 2) { // cout << "C\n"; for (int i = 0; i < n; i++) ans = max(ans, nums[i]); } return ans; }

Compilation message (stderr)

friend.cpp:19:1: error: expected initializer before 'int'
   19 | int dp[N][2], nums[N];
      | ^~~
friend.cpp: In function 'void IAmYourFriend(int, int)':
friend.cpp:22:2: error: 'paths' was not declared in this scope
   22 |  paths[x].pb(y);
      |  ^~~~~
friend.cpp: In function 'void MyFriendsAreYourFriends(int, int)':
friend.cpp:27:37: error: 'el' was not declared in this scope; did you mean 'll'?
   27 |   if (isFriend[y][i]) IAmYourFriend(el, x);
      |                                     ^~
      |                                     ll
friend.cpp: In function 'int solve(int, int)':
friend.cpp:34:13: error: 'dp' was not declared in this scope
   34 |  int& res = dp[pos][state];
      |             ^~
friend.cpp:36:16: error: 'nums' was not declared in this scope
   36 |  res = state * nums[pos];
      |                ^~~~
friend.cpp:37:17: error: 'paths' was not declared in this scope
   37 |  for (auto el : paths[pos]) {
      |                 ^~~~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:45:30: error: 'nums' was not declared in this scope; did you mean '_nums'?
   45 |  for (int i = 0; i < n; i++) nums[i] = _nums[i];
      |                              ^~~~
      |                              _nums
friend.cpp:66:12: error: 'nums' was not declared in this scope; did you mean '_nums'?
   66 |     sum += nums[el];
      |            ^~~~
      |            _nums
friend.cpp:75:10: error: 'dp' was not declared in this scope
   75 |   memset(dp, -1, sizeof(dp));
      |          ^~
friend.cpp:77:15: error: expected ')' before ';' token
   77 |    solve(1, 0);
      |               ^
      |               )
friend.cpp:76:12: note: to match this '('
   76 |   ans = max(
      |            ^
friend.cpp:79:3: error: expected primary-expression before ')' token
   79 |   );
      |   ^
friend.cpp:82:38: error: 'nums' was not declared in this scope; did you mean '_nums'?
   82 |   for (int i = 0; i < n; i++) ans += nums[i];
      |                                      ^~~~
      |                                      _nums
friend.cpp:85:46: error: 'nums' was not declared in this scope; did you mean '_nums'?
   85 |   for (int i = 0; i < n; i++) ans = max(ans, nums[i]);
      |                                              ^~~~
      |                                              _nums