| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1363346 | marcus328 | Permutation Game (APIO25_permgame) | C++20 | 1 ms | 420 KiB |
#include "permgame.h"
#include <vector>
#include <utility>
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)
#define ms(a,x) memset(a,x,sizeof(a))
#define ALL(c) (c).begin(),(c).end()
#define SZ(a) sizeof(a)
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
int Alice(int m, int e, std::vector<int> u, std::vector<int> v, int n, std::vector<int> p) {
int cnt = 0;
for(int i = 0; i < n; i++){
if(p[i] == i) cnt++;
}
vi g[n];
for(int i = 0; i < e; i++){
g[u[i]].pb(v[i]);
g[v[i]].pb(u[i]);
}
int start_idx = -1;
for(int i = 0; i < m; i++){
if(g[i].size() > 2){
return cnt;
}
if(g[i].size() == 1){
start_idx = i;
}
}
vb vis(n, 0);
vi t(m);
for(int i = 0; i < n; i++){
if(p[i] != i && !vis[i]){
vis[i] = 1;
t[start_idx] = i;
int temp = start_idx, last = -1;
int cur = p[i];
while(cur != i){
if(g[temp][0] != last){
last = temp;
temp = g[temp][0];
}else{
last = temp;
temp = g[temp][1];
}
t[temp] = cur;
vis[cur] = 1;
cur = p[cur];
if(g[temp].size() == 1){
int j = Bob(t);
cnt++;
if(p[t[u[j]]] == t[v[j]]){
int last = v[j];
while(g[last].size() != 1){
if(p[t[g[last][0]]] == t[last]){
t[last] = t[g[last][1]];
last = g[last][1];
}else{
t[last] = t[g[last][0]];
last = g[last][0];
}
}
temp = g[last][0];
}else{
int last = u[j];
while(g[last].size() != 1){
if(p[t[g[last][0]]] == t[last]){
t[last] = t[g[last][1]];
last = g[last][1];
}else{
t[last] = t[g[last][0]];
last = g[last][0];
}
}
temp = g[last][0];
}
}
}
}
}
return cnt;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
