Submission #1204481

#TimeUsernameProblemLanguageResultExecution timeMemory
1204481PlayVoltzWiring (IOI17_wiring)C++20
Compilation error
0 ms0 KiB
#include <cstdio> #include <stdio.h> #include <stdbool.h> #include <iostream> #include <map> #include <vector> #include <climits> #include <stack> #include <string> #include <queue> #include <algorithm> #include <set> #include <unordered_set> #include <unordered_map> #include <cmath> #include <cctype> #include <bitset> #include <iomanip> #include <cstring> #include <numeric> #include <cassert> using namespace std; #define int long long #define pii pair<int, int> #define mp make_pair #define pb push_back #define fi first #define se second vector<int> vect, p; vector<pii> ans; void dfs(set<int> &s){ if (s.size()<=1)return; int node=*(--s.end()), a=vect[node], b=p[node]; bool front=1; while (1){ if (vect[node]<vect[a]&&a<=vect[node])break; if (vect[node]<vect[b]&&b<=vect[node]){ front=0; break; } a=vect[a], b=p[b]; } set<int> temp; if (front){ int t=a; while (t!=node)s.erase(t), temp.insert(t), t=p[t]; ans.pb(mp(node, a)); swap(p[vect[node]], p[vect[a]]); swap(vect[node], vect[a]); } else{ int t=b; while (t!=node)t=vect[t], s.erase(t), temp.insert(t); ans.pb(mp(node, b)); swap(p[vect[node]], p[vect[b]]); swap(vect[node], vect[b]); } dfs(s); dfs(temp); } int32_t main(){ int n, k, res=0; cin>>n>>k; vect.resize(n+1); p.resize(n+1); for (int i=1; i<=n; ++i)cin>>vect[i], p[vect[i]]=i, res+=abs(vect[i]-i); vector<bool> visited(n+1, 0); for (int i=1; i<=n; ++i){ if (visited[i])continue; visited[i]=1; set<int> s; int node=vect[i]; s.insert(i); while (node!=i){ s.insert(node); visited[node]=1; node=vect[node]; } dfs(s); } cout<<ans.size()<<" "<<res/2+k*ans.size()<<"\n"; for (auto a:ans)cout<<a.fi<<" "<<a.se<<"\n"; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccdIGQ0I.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccuBx8ih.o:wiring.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccdIGQ0I.o: in function `main':
grader.cpp:(.text.startup+0x22b): undefined reference to `min_total_length(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status