Submission #436119

#TimeUsernameProblemLanguageResultExecution timeMemory
436119HediChehaidarFun Tour (APIO20_fun)C++17
26 / 100
18 ms2552 KiB
/* ID: hedichehaidar TASK: photo LANG: C++11 */ #include<bits/stdc++.h> #include "fun.h" typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef double db; ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (PGCD) ll lcm(ll a , ll b) {return (a * b) / gcd(a , b);} // least common multiple (PPCM) #define ss second #define ff first #define all(x) (x).begin() , (x).end() #define pb push_back #define vi vector<int> #define vii vector<pair<int,int>> #define vl vector<ll> #define vll vector<pair<ll,ll>> #define pii pair<int,int> #define pll pair<ll,ll> #define pdd pair<double,double> #define vdd vector<pdd> #define dte tuple<double , double , double> using namespace std; const int INF = 1000*1000*1000; // 1 e 9 const int MOD = INF + 7; const double EPS = 0.000000001; // 1 e -9 const ll inf = (ll)1e18; bool vis[505]; int dist[505][505]; int n; /*int hoursRequired(int i , int j){ cout << i << " " << j << endl; int x; cin>>x; return x; }*/ vi createFunTour(int N , int Q){ n = N; for(int i = 0 ; i < n ; i++){ for(int j = i + 1 ; j < n ; j++){ dist[i][j] = dist[j][i] = hoursRequired(i , j); } } int mx = 1; for(int i = 2 ; i < n ; i++){ if(dist[0][i] > dist[0][mx]) mx = i; } int cur = 0; for(int i = 0 ; i < n ; i++){ if(dist[mx][i] > dist[mx][cur]) cur = i; } vis[cur] = true; vi res; res.pb(cur); int nb = 1; while(nb < n){ int nxt = cur; // cout << cur << endl; for(int i = 0 ; i < n ; i++){ // cout << vis[i] << " " << dist[cur][i] << "\n"; if(dist[cur][i] > dist[cur][nxt] && !vis[i]) { nxt = i; } } vis[nxt] = true; res.pb(nxt); cur = nxt; nb++; } return res; } /*int main() { //ifstream fin ("race.in"); //ofstream fout ("race.out"); ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); int N; cin>>N; for(auto c : createFunTour(N , 400*1000)) cout << c << " " ; return 0; }*/ /* Think of : BS / DFS / BFS / SSSP / SCC / MSP / MAX FLOW / TOPSORT / LCA / MATRIX / DP(bitmask) / 2 POINTERS / SEG TREE / MATH / UN FIND / MO Read the statement CAREFULLY !! Make a GREADY APPROACH !!!! (start from highest / lowest) Make your own TESTS !! Be careful from CORNER CASES ! */
#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...