QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#481533#4688. Window ManagerGeothermalWA 1ms3836kbC++205.3kb2024-07-17 08:23:292024-07-17 08:23:30

Judging History

你现在查看的是最新测评结果

  • [2024-07-17 08:23:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3836kb
  • [2024-07-17 08:23:29]
  • 提交

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';

typedef array<ll, 5> squ;

ll Xmax, Ymax;

set<squ> sqs;

bool inter(squ A, squ B) {
    return max(A[0], B[0]) < min(A[0]+A[2], B[0]+B[2]) && max(A[1], B[1]) < min(A[1]+A[3], B[1]+B[3]);
}
bool cont(squ A, ll X, ll Y) {
    return A[0] <= X && A[0]+A[2] > X && A[1] <= Y && A[1]+A[3] > Y;
}

bool inBounds(squ A) {
    return A[0] >= 0 && A[1] >= 0 && A[0]+A[2] <= Xmax && A[1]+A[3] <= Ymax;
}

void swapXY() {
    set<squ> nxt;
    trav(a, sqs) {
        nxt.ins({a[1], a[0], a[3], a[2], a[4]});
    }
    swap(Xmax, Ymax);
    sqs = nxt;
}

void invX() {
    set<squ> nxt;
    trav(a, sqs) {
        nxt.ins({Xmax-a[0]-a[2], a[1], a[2], a[3], a[4]});
    }
    sqs = nxt;
}

void solve() {
    cin >> Xmax >> Ymax;

    string S;
    int cn = 0;
    while (cin >> S) {
        cn++;
        ll X, Y; cin >> X >> Y;
        if (S == "OPEN") {
            ll W, H; cin >> W >> H;
            squ nxt = {X, Y, W, H, cn};
            trav(a, sqs) {
                if (inter(a, nxt)) {
                    cout << "Command " << cn << ": OPEN - window does not fit" << nl; goto doneO;
                }
            }
            if (!inBounds(nxt)) {
                cout << "Command " << cn << ": OPEN - window does not fit" << nl; goto doneO;
            }
            sqs.ins(nxt);
            doneO:
            ;
        } else if (S == "CLOSE") {
            trav(a, sqs) {
                if (cont(a, X, Y)) {
                    sqs.erase(a);
                    goto doneC;
                }
            }
            cout << "Command " << cn << ": CLOSE - no window at given position" << nl;
            doneC:
            ;
        } else if (S == "RESIZE") {
            squ base = {-1,-1,-1,-1,-1};
            ll W, H; cin >> W >> H;
            trav(a, sqs) {
                if (cont(a, X, Y)) {
                    base = a;
                }
            }

            int cnt; squ nxt;
            if (base[0] == -1) {
                cout << "Command " << cn << ": RESIZE - no window at given position" << nl;
                goto doneR;
            }

            cnt = 0;
            nxt = base;
            nxt[2] = W; nxt[3] = H;
            trav(a, sqs) {
                if (inter(nxt, a)) cnt++;
            }
            if (!inBounds(nxt)) cnt+=2;
            if (cnt > 1) {
                cout << "Command " << cn << ": RESIZE - window does not fit" << nl;
                goto doneR;
            }

            sqs.erase(base);
            sqs.ins(nxt);
            doneR:
            ;
        } else {
            ll DX, DY; cin >> DX >> DY;
            bool flXY = false, flX = false;
            if (DY != 0) {
                swap(X, Y);
                swap(DX, DY);
                flXY = true;
                swapXY();
            }
            if (DX < 0) {
                X = Xmax - X - 1;
                DX *= -1;
                flX = true;
                invX();
            }

            vector<squ> ops;
            squ base = {-1,-1,-1,-1,-1};
            ll oop;
            trav(a, sqs) {
                if (cont(a, X, Y)) {
                    base = a;
                }
            }
            if (base[0] == -1) {
                cout << "Command " << cn << ": MOVE - no window at given position" << nl;
                goto doneM;
            }

            sqs.erase(base);
            ops.pb(base);
            trav(a, sqs) {
                if (a[0] > base[0] && max(a[1], base[1]) < min(a[1]+a[3], base[1]+base[3])) {
                    ops.pb(a);
                }
            }
            trav(a, ops) {
                sqs.erase(a);
            }
            sort(all(ops));

            ops[0][0] += DX;
            FOR(i, 1, sz(ops)) {
                ops[i][0] = max(ops[i][0], ops[i-1][0] + ops[i-1][2]);
            }
            oop = max(0ll, ops.back()[0]+ops.back()[2]-Xmax);
            if (oop) {
                cout << "Command " << cn << ": MOVE - moved " << DX-oop << " instead of " << DX << nl;
            }
            trav(a, ops) {
                a[0] -= oop;
            }

            trav(a, ops) {
                sqs.ins(a);
            }




            doneM:
            ;

            if (flX) {
                invX();
            }
            if (flXY) {
                swapXY();
            }
        }
    }

    vector<squ> res;
    trav(a, sqs) {
        res.pb({a[4],a[0],a[1],a[2],a[3]});
    }
    sort(all(res));
    cout << sz(res) << " window(s):" << nl;
    trav(a, res) {
        cout << a[1]<<" " << a[2] << " " << a[3] << " " << a[4] << nl;
    }
}

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

详细

Test #1:

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

input:

320 200
OPEN 50 50 10 10
OPEN 70 55 10 10
OPEN 90 50 10 10
RESIZE 55 55 40 40
RESIZE 55 55 15 15
MOVE 55 55 40 0
CLOSE 55 55
CLOSE 110 60
MOVE 95 55 0 -100

output:

Command 4: RESIZE - window does not fit
Command 7: CLOSE - no window at given position
Command 9: MOVE - moved 50 instead of 100
2 window(s):
90 0 15 15
115 50 10 10

result:

ok 6 lines

Test #2:

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

input:

10 10
OPEN 0 0 8 8
MOVE 0 0 5 0

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
2 0 8 8

result:

ok 3 lines

Test #3:

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

input:

10 10
OPEN 2 2 8 8
MOVE 3 3 -5 0

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
0 2 8 8

result:

ok 3 lines

Test #4:

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

input:

10 10
OPEN 2 2 8 8
MOVE 3 3 0 -5

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
2 0 8 8

result:

ok 3 lines

Test #5:

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

input:

10 10
OPEN 0 0 8 8
MOVE 0 0 0 5

output:

Command 2: MOVE - moved 2 instead of 5
1 window(s):
0 2 8 8

result:

ok 3 lines

Test #6:

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

input:

6000 6000
OPEN 5000 5000 5 5
OPEN 5000 4990 5 5
OPEN 5000 4980 5 5
OPEN 5000 4970 5 5
OPEN 5000 4960 5 5
OPEN 5000 4950 5 5
OPEN 5000 4940 5 5
OPEN 5000 4930 5 5
OPEN 5000 4920 5 5
OPEN 5000 4910 5 5
OPEN 5000 4900 5 5
OPEN 5000 4890 5 5
OPEN 5000 4880 5 5
OPEN 5000 4870 5 5
OPEN 5000 4860 5 5
OPEN ...

output:

200 window(s):
5000 1000 5 5
5000 995 5 5
5000 990 5 5
5000 985 5 5
5000 980 5 5
5000 975 5 5
5000 970 5 5
5000 965 5 5
5000 960 5 5
5000 955 5 5
5000 950 5 5
5000 945 5 5
5000 940 5 5
5000 935 5 5
5000 930 5 5
5000 925 5 5
5000 920 5 5
5000 915 5 5
5000 910 5 5
5000 905 5 5
5000 900 5 5
5000 895 5 ...

result:

ok 201 lines

Test #7:

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

input:

1000 1000
OPEN 0 0 10 10
OPEN 10 0 10 10
OPEN 20 0 10 10
OPEN 0 10 10 10
OPEN 10 10 10 10
OPEN 20 10 10 10
OPEN 0 20 10 10
OPEN 10 20 10 10
OPEN 20 20 10 10
CLOSE 19 19
CLOSE 20 20
CLOSE 0 10

output:

6 window(s):
0 0 10 10
10 0 10 10
20 0 10 10
20 10 10 10
0 20 10 10
10 20 10 10

result:

ok 7 lines

Test #8:

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

input:

1000 1000
OPEN 500 500 10 10
CLOSE 499 499
CLOSE 499 500
CLOSE 500 499
CLOSE 510 509
CLOSE 509 510
CLOSE 510 510
CLOSE 499 510
CLOSE 500 510
CLOSE 499 509
CLOSE 510 499
CLOSE 510 500
CLOSE 509 499

output:

Command 2: CLOSE - no window at given position
Command 3: CLOSE - no window at given position
Command 4: CLOSE - no window at given position
Command 5: CLOSE - no window at given position
Command 6: CLOSE - no window at given position
Command 7: CLOSE - no window at given position
Command 8: CLOSE -...

result:

ok 14 lines

Test #9:

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

input:

320 200

output:

0 window(s):

result:

ok single line: '0 window(s):'

Test #10:

score: -100
Wrong Answer
time: 0ms
memory: 3564kb

input:

1048576 1048576
OPEN 0 0 100 1048576
OPEN 1000 0 100 524288
OPEN 1000 524288 100 524288
OPEN 2000 0 100 262144
OPEN 2000 262144 100 262144
OPEN 2000 524288 100 262144
OPEN 2000 786432 100 262144
OPEN 3000 0 100 131072
OPEN 3000 131072 100 131072
OPEN 3000 262144 100 131072
OPEN 3000 393216 100 13107...

output:

Command 128: MOVE - moved 1035876 instead of 1048576
127 window(s):
1035876 0 100 1048576
1035976 0 100 524288
1036076 524288 100 524288
1036176 0 100 262144
1036276 262144 100 262144
1036376 524288 100 262144
1036476 786432 100 262144
1036576 0 100 131072
1036676 131072 100 131072
1036776 262144 10...

result:

wrong answer 1st lines differ - expected: 'Command 128: MOVE - moved 1047876 instead of 1048576', found: 'Command 128: MOVE - moved 1035876 instead of 1048576'