QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#178939 | #7119. Longest Trip | zhoukangyang# | 0 | 1ms | 4096kb | C++11 | 2.1kb | 2023-09-14 15:45:09 | 2024-04-28 08:55:24 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define ll long long
#define ull unsigned long long
#define sz(a) ((int) a.size())
#define vi vector<int>
#define me(a, x) memset(a, x, sizeof(a))
using namespace std;
const int N = 1 << 21, L = 5e5, mod = 998244353;
const ll inf = 1.5e18;
bool are_connected(vi A, vi B);
mt19937_64 orz;
vi longest_trip(int N, int D) {
vi a = {1}, b;
L(i, 2, N) {
if(orz() & 1) {
swap(a, b);
}
if(!sz(b)) {
b.emplace_back(i);
} else {
if(are_connected(vi{i}, vi{a.back()})) {
a.emplace_back(i);
} else if(are_connected(vi{i}, vi{b.back()})) {
b.emplace_back(i);
} else {
reverse(b.begin(), b.end());
for(auto&x : b) a.emplace_back(x);
b.clear();
}
}
}
if(sz(a) < sz(b)) {
swap(a, b);
}
if(!are_connected(a, b) || !sz(a) || !sz(b)) {
return sz(a) > sz(b) ? a : b;
}
vi q1 = vi{a[0], a.back()}, q2 = vi{b[0], b.back()};
if(q1.back() == a[0]) q1.pop_back();
if(q2.back() == b[0]) q2.pop_back();
if(are_connected(q1, q2)) {
for(int x : {a[0], a.back()})
for(int y : {b[0], b.back()}) if(are_connected(vi{x}, vi{y})) {
if(x == a.back()) reverse(a.begin(), a.end());
if(y == b.back()) reverse(b.begin(), b.end());
reverse(a.begin(), a.end());
for(auto&x : b) a.emplace_back(x);
return a;
}
return vi{};
}
int l = 0, r = sz(a) - 1, ans1 = -1, ans2 = -1;
while(l <= r) {
int mid = (l + r) >> 1;
vi P;
L(i, 0, mid) P.emplace_back(a[i]);
if(are_connected(P, b)) {
ans1 = mid, r = mid - 1;
} else {
l = mid + 1;
}
}
l = 0, r = sz(b) - 1;
while(l <= r) {
int mid = (l + r) >> 1;
vi P;
L(i, 0, mid) P.emplace_back(b[i]);
if(are_connected(vi{ans1}, P)) {
ans2 = mid, r = mid - 1;
} else {
l = mid + 1;
}
}
vi ans;
R(i, ans1 - 1, 0) ans.emplace_back(a[i]);
R(i, sz(a) - 1, ans1) ans.emplace_back(a[i]);
L(i, ans2, sz(b) - 1) ans.emplace_back(b[i]);
L(i, 0, ans2 - 1) ans.emplace_back(b[i]);
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3776kb
input:
341 3 3
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 3 1
result:
wrong answer invalid array
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 3816kb
input:
341 3 2
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 3 1
result:
wrong answer invalid array
Subtask #3:
score: 0
Wrong Answer
Test #19:
score: 0
Wrong Answer
time: 0ms
memory: 4096kb
input:
341 3 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 3 1
result:
wrong answer invalid array
Subtask #4:
score: 0
Wrong Answer
Test #83:
score: 0
Wrong Answer
time: 1ms
memory: 4088kb
input:
341 3 1
output:
3kC2Ia2048BfyJVGojMUKKtilctlZKcB 0 1 1 3 1
result:
wrong answer invalid array