Submission #1028958

#TimeUsernameProblemLanguageResultExecution timeMemory
1028958DorostWefAncient Books (IOI17_books)C++17
22 / 100
810 ms23120 KiB
#include "books.h" #include <bits/stdc++.h> #pragma GCC optimze ("O3, unroll-loops") #pragma GCC target ("avx2") using namespace std; typedef long long ll; const int N = 1023; bool vis[N]; vector <int> c[N]; int l[N], r[N]; int n; int dis[N][N]; long long minimum_walk(std::vector<int> p, int s) { long long ans = 0; n = (int)p.size(); for (int i = 0; i < n; i++) { ans += abs (p[i] - i); } int w = s; for (int i = 0; i < n; i++) { if (!vis[i]) { l[i] = i; r[i] = i; c[i] = {i}; int j = i; while (p[j] != i) { j = p[j]; if (j == s) w = i; l[i] = min(l[i], j); r[i] = max(r[i], j); c[i].push_back(j); vis[j] = true; } } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) dis[i][j] = N; else dis[i][j] = 0; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int x : c[j]) { if (x >= l[i] && x <= r[i]) { dis[i][j] = 0; } dis[i][j] = min(dis[i][j], abs(l[i] - x)); dis[i][j] = min(dis[i][j], abs(r[i] - x)); } } } for (int k = 0; k < n; k++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { dis[i][j] = min (dis[i][j], dis[i][k] + dis[k][j]); } } } int mx = 0; for (int j = 0; j < n; j++) { if (dis[w][j] != N && c[j].size() >= 2) { mx = max (mx, dis[w][j]); } } return ans + 2 * mx; }

Compilation message (stderr)

books.cpp:4: warning: ignoring '#pragma GCC optimze' [-Wunknown-pragmas]
    4 | #pragma GCC optimze ("O3, unroll-loops")
      |
#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...