# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
975910 | 2024-05-06T03:12:16 Z | vjudge1 | Star triangles (IZhO11_triangle) | C++17 | 1610 ms | 13796 KB |
#pragma GCC optimize ("Ofast") #include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pb push_back using namespace std; #define FUL(i, a, N) for(int i = a; i < N; i++) #define FUE(i, a, N) for(int i = a; i <= N; i++) int N, ans, temp; pair<int, int> titik[300002]; map<int, vector<int>> titikX, titikY; map<int, vector<int>> ::iterator it; int main(){ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> N; FUE(i, 1, N){ cin >> titik[i].fi >> titik[i].se; } // preprocessing titikX[titik[1].fi].pb(titik[1].se); titikY[titik[1].se].pb(titik[1].fi); titikX[titik[2].fi].pb(titik[2].se); titikY[titik[2].se].pb(titik[2].fi); FUE(i, 3, N){ temp = 0; it = titikX.find(titik[i].fi); if(it != titikX.end()){ FUL(i, 0, it->se.size()){ temp += titikY[it->se[i]].size() - 1; } } it = titikY.find(titik[i].se); if(it != titikY.end()){ FUL(i, 0, it->se.size()){ temp += titikX[it->se[i]].size() - 1; } } temp += titikX[titik[i].fi].size() * titikY[titik[i].se].size(); ans += temp; titikX[titik[i].fi].pb(titik[i].se); titikY[titik[i].se].pb(titik[i].fi); } cout << ans; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 344 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 2 ms | 348 KB | Output is correct |
11 | Correct | 4 ms | 348 KB | Output is correct |
12 | Correct | 323 ms | 1452 KB | Output is correct |
13 | Correct | 1610 ms | 1768 KB | Output is correct |
14 | Correct | 10 ms | 2392 KB | Output is correct |
15 | Correct | 172 ms | 9812 KB | Output is correct |
16 | Correct | 167 ms | 9808 KB | Output is correct |
17 | Correct | 146 ms | 9808 KB | Output is correct |
18 | Correct | 156 ms | 9588 KB | Output is correct |
19 | Correct | 705 ms | 13176 KB | Output is correct |
20 | Correct | 408 ms | 11776 KB | Output is correct |
21 | Correct | 796 ms | 13768 KB | Output is correct |
22 | Correct | 858 ms | 13796 KB | Output is correct |