Submission #645782

#TimeUsernameProblemLanguageResultExecution timeMemory
645782ghostwriter친구 (IOI14_friend)C++14
19 / 100
22 ms1452 KiB
#include "friend.h" #include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #include "grader.cpp" #endif #define ft front #define bk back #define st first #define nd second #define ins insert #define ers erase #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define bg begin #define ed end #define all(x) (x).bg(), (x).ed() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i)) #define FSN(i, n) for (int (i) = (n) - 1; (i) >= 0; --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* ---------------------------------------------------------------- END OF TEMPLATE ---------------------------------------------------------------- Tran The Bao - ghostwriter Training for VOI23 gold medal ---------------------------------------------------------------- DIT ME CHUYEN BAO LOC ---------------------------------------------------------------- */ namespace subtask1 { const int N = 10; int c[N], d1[N][N], rs = 0; void brute(int n, int confidence[], int i, int s) { if (i >= n) { bool ok = 1; FRN(x, n) FRN(y, n) { if (x == y || !c[x] || !c[y]) continue; if (d1[x][y]) ok = 0; } if (ok) rs = max(rs, s); return; } brute(n, confidence, i + 1, s); c[i] = 1; brute(n, confidence, i + 1, s + confidence[i]); c[i] = 0; } int findSample(int n, int confidence[], int host[], int protocol[]) { FOR(i, 1, n - 1) { int h = host[i], p = protocol[i]; if (!p) d1[i][h] = d1[h][i] = 1; else if (p == 1) { FRN(j, n) if (d1[h][j]) d1[i][j] = d1[j][i] = 1; } else { FRN(j, n) if (d1[h][j]) d1[i][j] = d1[j][i] = 1; d1[i][h] = d1[h][i] = 1; } } brute(n, confidence, 0, 0); return rs; } } namespace subtask2 { int rs = 0; int findSample(int n, int confidence[], int host[], int protocol[]) { FRN(i, n) rs += confidence[i]; return rs; } } namespace solution { int findSample(int n, int confidence[], int host[], int protocol[]) { return 1; } } int findSample(int n, int confidence[], int host[], int protocol[]) { if (n <= 10) return subtask1::findSample(n, confidence, host, protocol); bool sub2 = (n <= 1e3), sub3 = (n <= 1e3), sub4 = (n <= 1e3); FOR(i, 1, n - 1) { if (protocol[i] != 1) sub2 = 0; if (protocol[i] != 2) sub3 = 0; if (protocol[i] != 0) sub4 = 0; } if (sub2) return subtask2::findSample(n, confidence, host, protocol); return solution::findSample(n, confidence, host, protocol); } /* 6 13 3 6 20 10 15 0 0 0 1 1 2 2 1 0 0 2 10 20 0 1 ---------------------------------------------------------------- From Benq: stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH ---------------------------------------------------------------- */

Compilation message (stderr)

friend.cpp: In function 'void subtask1::brute(int, int*, int, int)':
friend.cpp:34:28: warning: unnecessary parentheses in declaration of 'x' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
friend.cpp:57:4: note: in expansion of macro 'FRN'
   57 |    FRN(x, n)
      |    ^~~
friend.cpp:34:28: warning: unnecessary parentheses in declaration of 'y' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
friend.cpp:58:4: note: in expansion of macro 'FRN'
   58 |    FRN(y, n) {
      |    ^~~
friend.cpp: In function 'int subtask1::findSample(int, int*, int*, int*)':
friend.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
friend.cpp:71:3: note: in expansion of macro 'FOR'
   71 |   FOR(i, 1, n - 1) {
      |   ^~~
friend.cpp:34:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
friend.cpp:75:5: note: in expansion of macro 'FRN'
   75 |     FRN(j, n)
      |     ^~~
friend.cpp:34:28: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
friend.cpp:80:5: note: in expansion of macro 'FRN'
   80 |     FRN(j, n)
      |     ^~~
friend.cpp: In function 'int subtask2::findSample(int, int*, int*, int*)':
friend.cpp:34:28: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   34 | #define FRN(i, n) for (int (i) = 0; (i) < (n); ++(i))
      |                            ^
friend.cpp:93:3: note: in expansion of macro 'FRN'
   93 |   FRN(i, n) rs += confidence[i];
      |   ^~~
friend.cpp: In function 'int findSample(int, int*, int*, int*)':
friend.cpp:32:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   32 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
friend.cpp:105:2: note: in expansion of macro 'FOR'
  105 |  FOR(i, 1, n - 1) {
      |  ^~~
friend.cpp:104:26: warning: variable 'sub3' set but not used [-Wunused-but-set-variable]
  104 |  bool sub2 = (n <= 1e3), sub3 = (n <= 1e3), sub4 = (n <= 1e3);
      |                          ^~~~
friend.cpp:104:45: warning: variable 'sub4' set but not used [-Wunused-but-set-variable]
  104 |  bool sub2 = (n <= 1e3), sub3 = (n <= 1e3), sub4 = (n <= 1e3);
      |                                             ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...