Submission #516963

#TimeUsernameProblemLanguageResultExecution timeMemory
516963mansurDuathlon (APIO18_duathlon)C++17
5 / 100
1123 ms609512 KiB
#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], cur; int tin[N], tout[N], sz[N], timer; void calc(int u, int p) { cur.pb(u); was[u] = 1; sz[u] = 1; tin[u] = timer++; for (auto e: adj[u]) { if (e != p) { calc(e, u); sz[u] += sz[e]; } } tout[u] = timer; } bool is(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; } 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]) { calc(i, i); for (auto s: cur) { for (auto c: cur) { if (s == c) continue; if (is(s, c)) { ans += sz[c] - 1; }else if (is(c, s)) { ans += sz[i] - sz[c]; }else { ans += sz[c] - 1; } } } cur.clear(); } } cout << ans; } }

Compilation message (stderr)

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:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main() {
      | ^~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...