# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
966500 | 2024-04-20T02:01:57 Z | Requiem | Vrtić (COCI18_vrtic) | C++17 | 2000 ms | 197888 KB |
#include<bits/stdc++.h> #define int long long #define pb push_back #define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #define MOD 1000000007 #define INF 1e18 #define fi first #define se second #define FOR(i,a,b) for(int i=a;i<=b;i++) #define FORD(i,a,b) for(int i=a;i>=b;i--) #define sz(a) ((int)(a).size()) #define endl '\n' #define pi 3.14159265359 #define TASKNAME "vrtic" template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; } template<typename T> bool minimize(T &res, const T &val) { if (res >= val){ res = val; return true; }; return false; } using namespace std; typedef pair<int,int> ii; typedef pair<int,ii> iii; typedef vector<int> vi; const int MAXN = 159; int n; int best_friend[MAXN], bag_of_candy[MAXN]; namespace subtask1{ bool checkSubtask1(){ for(int i = 1; i <= n; i++){ if (best_friend[i] != i % n + 1) return false; } return true; } int arr[MAXN]; void solveSubtask1(){ int res = 0, splitting_point = 0; sort(bag_of_candy + 1, bag_of_candy + 1 + n); int cur = 0; for(int i = 3; i <= n; i++){ maximize(res, abs(bag_of_candy[i] - bag_of_candy[i - 2])); } cout << res << endl; for(int i = 1; i <= n; i += 2){ cout << bag_of_candy[i] << ' '; } for(int i = n - (n & 1); i > 0; i -= 2){ cout << bag_of_candy[i] << ' '; } cout << endl; } } namespace subtask2{ //not usable yet bool checkSubtask2(){ return n <= 20; } void solveSubtask2(){ int permutation[21], answer[21]; iota(permutation + 1, permutation + 1 + n, 1); int res = INF; do{ int cur = 0; for(int i = 1; i <= n; i++){ maximize(cur, abs( bag_of_candy[permutation[i]] - bag_of_candy[permutation[best_friend[i]]] ) ); } if (minimize(res, cur)){ cout << "RES: " << res << endl; for(int i = 1; i <= n; i++){ answer[i] = permutation[i]; cout << bag_of_candy[permutation[i]] << ' '; } cout << endl; } }while(next_permutation(permutation + 1, permutation + 1 + n)); cout << res << endl; for(int i = 1; i <= n; i++){ cout << bag_of_candy[answer[i]] << ' '; } cout << endl; } } main() { fast; if (fopen(TASKNAME".inp","r")){ freopen(TASKNAME".inp","r",stdin); freopen(TASKNAME".out","w",stdout); } cin >> n; for(int i = 1; i <= n; i++){ cin >> best_friend[i]; } for(int i = 1; i <= n; i++){ cin >> bag_of_candy[i]; } if (subtask1::checkSubtask1()) return subtask1::solveSubtask1(), 0; if (subtask2::checkSubtask2()) return subtask2::solveSubtask2(), 0; } /** Warning: - MLE / TLE? - Gioi han mang? - Gia tri max phai luon gan cho -INF - long long co can thiet khong? - tran mang. - code can than hon - Nho sinh test de tranh RTE / TLE --> Coi lai truoc khi nop **/
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2036 ms | 155064 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2017 ms | 197888 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2062 ms | 4176 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 500 KB | Unexpected end of file - int64 expected |
2 | Halted | 0 ms | 0 KB | - |