Submission #516918

# Submission time Handle Problem Language Result Execution time Memory
516918 2022-01-22T08:22:13 Z mansur Duathlon (APIO18_duathlon) C++17
13 / 100
59 ms 29068 KB
#include<bits/stdc++.h>	
 
#pragma optimize ("g",on)
#pragma GCC optimize ("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
 
//01001101 01100001 01101011 01101000 01100001  01100111 01100001 01111001 
 
using namespace std;
 
#define all(a) a.begin(), a.end()                                                   
#define rall(a) a.rbegin(), a.rend()
#define ll long long
#define pb push_back
#define sz(a) a.size()
#define nl '\n'
#define popb pop_back()                                                                   
#define ld double
#define ull unsigned long long
#define ff first                                         
#define ss second  
#define fix fixed << setprecision
#define pii pair<int, int>                          
#define E exit (0)
#define int long long
 
const int inf = 1e15, N = 1e6, mod = 998244353;                    
 
double eps = 1e-6;
 
vector<pii> dir = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
 
bool can[(1 << 10)][10][10], was[N];
 
vector<int> h[10][10], adj[N];
 
int d, v;
 
void dfs(int u) {
	was[u] = 1;
	v++;
	for (auto e: adj[u]) {
		d++;
		if (!was[e]) {
			dfs(e);
		}
	}
}
 
main() {                                                         
	//freopen("F.in", "r", stdin);                                                                                     
	//freopen("F.out", "w", stdout);                                                                                     
	ios_base::sync_with_stdio(NULL);                                                                                
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	if (n <= 10) {
		for (int i = 0; i < n; i++) {
			can[(1 << i)][i][i] = 1;
		}
		for (int mask = 1; mask < (1 << n); mask++) {
			for (int s = 0; s < n; s++) {
				if (!(mask >> s & 1)) continue;
				for (int f = 0; f < n; f++) {
					if (!(mask >> f & 1) || f == s) continue;
					for (auto e: adj[f]) {
						if (!(mask >> e & 1)) continue;
						can[mask][s][f] |= can[mask ^ (1 << f)][s][e];
					}
					if (can[mask][s][f]) {
						h[s][f].pb(mask);
					}
				}
			}
		}
		int ans = 0;
		for (int s = 0; s < n; s++) {
			for (int c = 0; c < n; c++) {
				for (int f = 0; f < n; f++) {
					if (f == c || f == s || s == c) continue;
					bool ok = 0;
					for (auto a: h[s][c]) {
						for (auto b: h[c][f]) {
							if ((a & b) == (1 << c)) ok = 1;
							if (ok) break;
						}
						if (ok) break;
					}
					ans += ok;
				}
			}
		}
		cout << ans;
	}else {
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (!was[i]) {
				v = 0, d = 0;
			 	dfs(i);
			 	d /= 2;
			 	if (v < 3) continue;
			 	if (d == v) {
			 		ans += (v - 1) * (v - 2) * v;
			 		continue;	
			 	}
			 	for (int j = 1; j <= v - 2; j++) {
			 		ans += (v - j) * (v - j - 1);	
				}
			}
		}
		cout << ans;
	}
}

Compilation message

count_triplets.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize ("g",on)
      | 
count_triplets.cpp:9: warning: ignoring '#pragma comment ' [-Wunknown-pragmas]
    9 | #pragma comment(linker, "/stack:200000000")
      | 
count_triplets.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 12 ms 23884 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 13 ms 23932 KB Output is correct
9 Correct 14 ms 24012 KB Output is correct
10 Correct 14 ms 24012 KB Output is correct
11 Correct 13 ms 23884 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 14 ms 23876 KB Output is correct
14 Correct 13 ms 23884 KB Output is correct
15 Correct 13 ms 23884 KB Output is correct
16 Correct 12 ms 23868 KB Output is correct
17 Correct 13 ms 23860 KB Output is correct
18 Correct 13 ms 23820 KB Output is correct
19 Correct 16 ms 23896 KB Output is correct
20 Correct 17 ms 23884 KB Output is correct
21 Correct 12 ms 23884 KB Output is correct
22 Correct 13 ms 23884 KB Output is correct
23 Correct 13 ms 23756 KB Output is correct
24 Correct 13 ms 23812 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 13 ms 23804 KB Output is correct
27 Correct 14 ms 23756 KB Output is correct
28 Correct 14 ms 23740 KB Output is correct
29 Correct 13 ms 23888 KB Output is correct
30 Correct 13 ms 23836 KB Output is correct
31 Correct 14 ms 23852 KB Output is correct
32 Correct 13 ms 23884 KB Output is correct
33 Correct 17 ms 23756 KB Output is correct
34 Correct 12 ms 23756 KB Output is correct
35 Correct 13 ms 23832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 12 ms 23884 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 13 ms 23932 KB Output is correct
9 Correct 14 ms 24012 KB Output is correct
10 Correct 14 ms 24012 KB Output is correct
11 Correct 13 ms 23884 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 14 ms 23876 KB Output is correct
14 Correct 13 ms 23884 KB Output is correct
15 Correct 13 ms 23884 KB Output is correct
16 Correct 12 ms 23868 KB Output is correct
17 Correct 13 ms 23860 KB Output is correct
18 Correct 13 ms 23820 KB Output is correct
19 Correct 16 ms 23896 KB Output is correct
20 Correct 17 ms 23884 KB Output is correct
21 Correct 12 ms 23884 KB Output is correct
22 Correct 13 ms 23884 KB Output is correct
23 Correct 13 ms 23756 KB Output is correct
24 Correct 13 ms 23812 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 13 ms 23804 KB Output is correct
27 Correct 14 ms 23756 KB Output is correct
28 Correct 14 ms 23740 KB Output is correct
29 Correct 13 ms 23888 KB Output is correct
30 Correct 13 ms 23836 KB Output is correct
31 Correct 14 ms 23852 KB Output is correct
32 Correct 13 ms 23884 KB Output is correct
33 Correct 17 ms 23756 KB Output is correct
34 Correct 12 ms 23756 KB Output is correct
35 Correct 13 ms 23832 KB Output is correct
36 Correct 13 ms 23756 KB Output is correct
37 Incorrect 12 ms 23756 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 29052 KB Output is correct
2 Correct 59 ms 29068 KB Output is correct
3 Correct 50 ms 28004 KB Output is correct
4 Correct 54 ms 28448 KB Output is correct
5 Correct 56 ms 27692 KB Output is correct
6 Correct 52 ms 27592 KB Output is correct
7 Correct 54 ms 27428 KB Output is correct
8 Correct 55 ms 27464 KB Output is correct
9 Correct 53 ms 27100 KB Output is correct
10 Correct 50 ms 27340 KB Output is correct
11 Correct 43 ms 26936 KB Output is correct
12 Correct 44 ms 26828 KB Output is correct
13 Correct 46 ms 26852 KB Output is correct
14 Correct 45 ms 26868 KB Output is correct
15 Correct 40 ms 26432 KB Output is correct
16 Correct 33 ms 26316 KB Output is correct
17 Correct 12 ms 23884 KB Output is correct
18 Correct 13 ms 23916 KB Output is correct
19 Correct 13 ms 23904 KB Output is correct
20 Correct 13 ms 23804 KB Output is correct
21 Correct 13 ms 23884 KB Output is correct
22 Correct 15 ms 23884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 23784 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 52 ms 27568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 27564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 12 ms 23884 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 13 ms 23932 KB Output is correct
9 Correct 14 ms 24012 KB Output is correct
10 Correct 14 ms 24012 KB Output is correct
11 Correct 13 ms 23884 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 14 ms 23876 KB Output is correct
14 Correct 13 ms 23884 KB Output is correct
15 Correct 13 ms 23884 KB Output is correct
16 Correct 12 ms 23868 KB Output is correct
17 Correct 13 ms 23860 KB Output is correct
18 Correct 13 ms 23820 KB Output is correct
19 Correct 16 ms 23896 KB Output is correct
20 Correct 17 ms 23884 KB Output is correct
21 Correct 12 ms 23884 KB Output is correct
22 Correct 13 ms 23884 KB Output is correct
23 Correct 13 ms 23756 KB Output is correct
24 Correct 13 ms 23812 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 13 ms 23804 KB Output is correct
27 Correct 14 ms 23756 KB Output is correct
28 Correct 14 ms 23740 KB Output is correct
29 Correct 13 ms 23888 KB Output is correct
30 Correct 13 ms 23836 KB Output is correct
31 Correct 14 ms 23852 KB Output is correct
32 Correct 13 ms 23884 KB Output is correct
33 Correct 17 ms 23756 KB Output is correct
34 Correct 12 ms 23756 KB Output is correct
35 Correct 13 ms 23832 KB Output is correct
36 Correct 13 ms 23756 KB Output is correct
37 Incorrect 12 ms 23756 KB Output isn't correct
38 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 12 ms 23756 KB Output is correct
4 Correct 14 ms 23720 KB Output is correct
5 Correct 12 ms 23756 KB Output is correct
6 Correct 12 ms 23884 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 13 ms 23932 KB Output is correct
9 Correct 14 ms 24012 KB Output is correct
10 Correct 14 ms 24012 KB Output is correct
11 Correct 13 ms 23884 KB Output is correct
12 Correct 13 ms 23900 KB Output is correct
13 Correct 14 ms 23876 KB Output is correct
14 Correct 13 ms 23884 KB Output is correct
15 Correct 13 ms 23884 KB Output is correct
16 Correct 12 ms 23868 KB Output is correct
17 Correct 13 ms 23860 KB Output is correct
18 Correct 13 ms 23820 KB Output is correct
19 Correct 16 ms 23896 KB Output is correct
20 Correct 17 ms 23884 KB Output is correct
21 Correct 12 ms 23884 KB Output is correct
22 Correct 13 ms 23884 KB Output is correct
23 Correct 13 ms 23756 KB Output is correct
24 Correct 13 ms 23812 KB Output is correct
25 Correct 13 ms 23756 KB Output is correct
26 Correct 13 ms 23804 KB Output is correct
27 Correct 14 ms 23756 KB Output is correct
28 Correct 14 ms 23740 KB Output is correct
29 Correct 13 ms 23888 KB Output is correct
30 Correct 13 ms 23836 KB Output is correct
31 Correct 14 ms 23852 KB Output is correct
32 Correct 13 ms 23884 KB Output is correct
33 Correct 17 ms 23756 KB Output is correct
34 Correct 12 ms 23756 KB Output is correct
35 Correct 13 ms 23832 KB Output is correct
36 Correct 13 ms 23756 KB Output is correct
37 Incorrect 12 ms 23756 KB Output isn't correct
38 Halted 0 ms 0 KB -