QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#531826#2337. AzulejosSwarthmore#AC ✓440ms40388kbC++202.2kb2024-08-24 22:31:442024-08-24 22:31:45

Judging History

This is the latest submission verdict.

  • [2024-08-24 22:31:45]
  • Judged
  • Verdict: AC
  • Time: 440ms
  • Memory: 40388kb
  • [2024-08-24 22:31:44]
  • Submitted

answer

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b) - 1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a) - 1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

void solve() {
    int N; cin >> N;
    vector<array<int, 3>> A[2];
    F0R(i, 2) {
        A[i] = vector<array<int, 3>>(N);
    }
    F0R(i, 2) {
        F0R(j, N) {
            cin >> A[i][j][0];
        }
        F0R(j, N) cin >> A[i][j][1];
        F0R(j, N) A[i][j][2] = j+1;
        sort(all(A[i]));
    }
    set<pi> cur[2];
    vi ans[2];
    F0R(i, N) {
        F0R(j, 2) {
            if (sz(cur[j]) == 0) {
                FOR(k, i, N) {
                    if (A[j][k][0] != A[j][i][0]) break;
                    cur[j].ins({A[j][k][1], A[j][k][2]});
                }
            }
        }

        if (sz(cur[0]) <= sz(cur[1])) {
            // back row
            pi v = *cur[0].begin();
            cur[0].erase(v);
            auto it = cur[1].lb({v.f, -1});
            if (it == cur[1].begin()) {
                cout << "impossible" << nl; return;
            }
            ans[0].pb(v.s);
            it--;
            ans[1].pb(it->s);
            cur[1].erase(it);
        } else {
            pi v = *cur[1].begin(); cur[1].erase(v);
            auto it = cur[0].lb({v.f+1, -1});
            if (it == cur[0].end()) {
                cout << "impossible" << nl; return;
            }
            ans[1].pb(v.s);
            ans[0].pb(it->s);
            cur[0].erase(it);
        }
    }
    F0R(i, 2) {
        F0R(j, N) {
            cout << ans[i][j] << " ";
        }
        cout << nl;
    }
}


int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3876kb

Test #2:

score: 0
Accepted
time: 0ms
memory: 3880kb

Test #3:

score: 0
Accepted
time: 0ms
memory: 3876kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 3844kb

Test #5:

score: 0
Accepted
time: 0ms
memory: 3644kb

Test #6:

score: 0
Accepted
time: 0ms
memory: 3576kb

Test #7:

score: 0
Accepted
time: 0ms
memory: 3876kb

Test #8:

score: 0
Accepted
time: 0ms
memory: 3840kb

Test #9:

score: 0
Accepted
time: 0ms
memory: 3640kb

Test #10:

score: 0
Accepted
time: 0ms
memory: 3588kb

Test #11:

score: 0
Accepted
time: 0ms
memory: 3808kb

Test #12:

score: 0
Accepted
time: 252ms
memory: 38172kb

Test #13:

score: 0
Accepted
time: 0ms
memory: 3592kb

Test #14:

score: 0
Accepted
time: 1ms
memory: 3656kb

Test #15:

score: 0
Accepted
time: 0ms
memory: 4360kb

Test #16:

score: 0
Accepted
time: 0ms
memory: 3616kb

Test #17:

score: 0
Accepted
time: 0ms
memory: 3812kb

Test #18:

score: 0
Accepted
time: 0ms
memory: 3580kb

Test #19:

score: 0
Accepted
time: 0ms
memory: 3528kb

Test #20:

score: 0
Accepted
time: 0ms
memory: 3808kb

Test #21:

score: 0
Accepted
time: 0ms
memory: 3676kb

Test #22:

score: 0
Accepted
time: 49ms
memory: 6520kb

Test #23:

score: 0
Accepted
time: 55ms
memory: 9792kb

Test #24:

score: 0
Accepted
time: 70ms
memory: 9612kb

Test #25:

score: 0
Accepted
time: 38ms
memory: 6576kb

Test #26:

score: 0
Accepted
time: 210ms
memory: 38324kb

Test #27:

score: 0
Accepted
time: 44ms
memory: 10352kb

Test #28:

score: 0
Accepted
time: 59ms
memory: 10180kb

Test #29:

score: 0
Accepted
time: 48ms
memory: 10200kb

Test #30:

score: 0
Accepted
time: 35ms
memory: 10272kb

Test #31:

score: 0
Accepted
time: 440ms
memory: 40388kb

Test #32:

score: 0
Accepted
time: 68ms
memory: 10208kb

Test #33:

score: 0
Accepted
time: 339ms
memory: 38156kb