| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1332259 | hauserl | A String Problem (EGOI25_stringproblem) | C++20 | 3 ms | 1604 KiB |
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
using namespace std;
int main() {
ll N; scanf("%d",&N);
ll TN = N*2;
vector<pair<ll, ll>> strings(N);
vector<ll> circle(2*N);
for (ll i = 0; i < N; i++) {
ll a,b; scanf("%lld %lld",&a, &b);
strings[i] = {a,b};
circle[a] = i;
circle[b] = i;
}
ll maxParallelCount = LONG_LONG_MIN;
ll bAxis = 1;
vector<ll> counts(TN,0); // axis
for (ll i = 0; i < TN; i++) {
// ein pin gerade einer ungerade -> sonst falsch
ll P1 = strings[i].f;
ll P2 = strings[i].s;
if ((P1+P2)%2 != 1) continue;
// ll axis = ((min(P1, P2) + (max(P1, P2) - min(P1, P2))/2)) % N;
ll axis = (P1 + P2) % TN;
if (axis%2 != 1) continue;
counts[axis]++;
if (counts[axis] > maxParallelCount) {
maxParallelCount = counts[axis];
bAxis = axis;
}
}
// immer irgendwo bei nicht parallelen anfangen und die lücke die entsteht mit dem gegenüber füllen
vector<tuple<ll, ll, ll>> moves;
vector<bool> doneString(N);
vector<bool> donePin(2*N);
for (ll i = 0; i < 2*N; i++) {
ll string = circle[i];
if (doneString[string] || donePin[i]) continue;
doneString[string] = true;
// ll second = (((bAxis + 1) % TN - (i - bAxis)) + TN) % TN;
ll second = (bAxis - i + TN ) % TN;
ll prevSecond = strings[string].f == i ? strings[string].s : strings[string].f;
if (second == prevSecond) {
doneString[string] = true;
donePin[i] = true;
donePin[second] = true;
continue;
}
moves.push_back({string, prevSecond, second});
donePin[i] = true;
donePin[second] = true;
// ll oppositePrevSecond = (((bAxis + 1) % TN - (prevSecond - bAxis)) + TN) % TN;
ll oppositePrevSecond = (bAxis - prevSecond + TN) %TN;
ll string2 = circle[oppositePrevSecond];
while (!doneString[string2]) {
doneString[string2]= true;
second = prevSecond;
prevSecond = strings[string2].f == oppositePrevSecond ? strings[string2].s : strings[string2].f;
moves.push_back({string2, prevSecond, second});
donePin[second] = true;
donePin[oppositePrevSecond] = true;
// oppositePrevSecond = (((bAxis + 1) % TN - (prevSecond - bAxis)) + TN) % TN;
oppositePrevSecond = (bAxis - prevSecond + TN) %TN;
if (oppositePrevSecond == prevSecond) oppositePrevSecond++;
oppositePrevSecond %= TN;
string2 = circle[oppositePrevSecond];
}
}
printf("%lld \n", moves.size());
for (ll i = 0; i < moves.size(); i++) {
printf("%lld %lld %lld\n", get<0>(moves[i]), get<1>(moves[i]), get<2>(moves[i]));
}
return 0;
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
