Submission #645786

#TimeUsernameProblemLanguageResultExecution timeMemory
645786ghostwriterFriend (IOI14_friend)C++14
27 / 100
25 ms1384 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 subtask3 {
	int rs = 0;
	int findSample(int n, int confidence[], int host[], int protocol[]) {
		FRN(i, n) rs = max(rs, confidence[i]);
		return rs;
	}
}
namespace subtask4 {
	const int N = 1e3;
	int sum = 0, confidence[N];
	vi adj[N];
	int rs = 0;
	void dfs(int u, int p, bool h) {
		if (h) rs += confidence[u];
		EACH(v, adj[u]) {
			if (v == p) continue;
			dfs(v, u, h ^ 1);
		}
	}
	int findSample(int n, int confidence[], int host[], int protocol[]) {
		FRN(i, n) subtask4::confidence[i] = confidence[i];
		FOR(i, 1, n - 1) {
			int u = i, v = host[i];
			adj[u].pb(v);
			adj[v].pb(u);
		}
		FRN(i, n) sum += confidence[i];
		dfs(0, -1, 0);
		return max(rs, sum - 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);
	if (sub3) return subtask3::findSample(n, confidence, host, protocol);
	if (sub4) return subtask4::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

2
10 20
0 0
----------------------------------------------------------------
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 subtask3::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:100:3: note: in expansion of macro 'FRN'
  100 |   FRN(i, n) rs = max(rs, confidence[i]);
      |   ^~~
friend.cpp: In function 'void subtask4::dfs(int, int, bool)':
friend.cpp:36:31: warning: unnecessary parentheses in declaration of 'v' [-Wparentheses]
   36 | #define EACH(i, x) for (auto &(i) : (x))
      |                               ^
friend.cpp:111:3: note: in expansion of macro 'EACH'
  111 |   EACH(v, adj[u]) {
      |   ^~~~
friend.cpp: In function 'int subtask4::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:117:3: note: in expansion of macro 'FRN'
  117 |   FRN(i, n) subtask4::confidence[i] = confidence[i];
      |   ^~~
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:118:3: note: in expansion of macro 'FOR'
  118 |   FOR(i, 1, n - 1) {
      |   ^~~
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:123:3: note: in expansion of macro 'FRN'
  123 |   FRN(i, n) sum += 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:136:2: note: in expansion of macro 'FOR'
  136 |  FOR(i, 1, n - 1) {
      |  ^~~
#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...