QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424120#8106. Mosaic_LiMLE_WA 1ms5696kbC++143.1kb2024-05-28 22:03:382024-05-28 22:03:39

Judging History

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

  • [2024-05-28 22:03:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5696kb
  • [2024-05-28 22:03:38]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define db double
#define FOR(i, s, t) for(int i = (s); i <= (t); ++i)
#define ROF(i, s, t) for(int i = (s); i >= (t); --i)
#define IL inline
#define pii pair<int, int>
#define mkp make_pair
#define fi first
#define se second
#define pb push_back
#define ls (x << 1)
#define rs ((x << 1) | 1)
#define mid ((l + r) >> 1)

using namespace std;

const int N = 1e6 + 5;
const int M = 1e9 + 7;
const int inf = 1e16;

struct seg {
    int l, r;
    int h;

    bool operator <(const seg &s)const {
        if(l != s.l) return l < s.l;
        else if(r != s.r) return r < s.r;
        else return h < s.h;
    }
};

struct node {
    int x, y, id;
};

int n, len[N];
node a[N];
set<seg> S;
set<seg>::iterator i1, i2, i3;

IL bool chk(int R) {
    // cout << R << '\n';
    S.clear(); S.insert((seg){0, R, 0});
    FOR(i, 1, n) {
        int x = a[i].x, y = a[i].y, id = a[i].id;
        // cout << i << '\n';
        // cout << x << ' ' << y << '\n';
        // for(seg s : S) {
        //     cout << s.l << ' ' << s.r << ' ' << s.h << '\n';
        // }
        i1 = i2 = S.upper_bound((seg){x, R + 1, 0}); i1--;
        if((*i1).h != y) return 0;
        len[id] = (*i1).r - x + 1;
        if(len[id] <= 0) return 0;
        if(i1 == S.begin() && (*i1).l < x) { //不会和左侧合并
            seg tmp = (*i1); S.erase(i1);
            if(tmp.l < x) S.insert((seg){tmp.l, x - 1, tmp.h});
            tmp.l = x, tmp.h += len[id];
            if(i2 != S.end() && (*i2).h == tmp.h) tmp.r = (*i2).r, S.erase(i2);
            S.insert(tmp);
        }
        else {
            seg tmp = (*i1); i3 = i1; i3--; S.erase(i1);
            tmp.l = x, tmp.h += len[id];
            if(i2 != S.end() && (*i2).h == tmp.h) tmp.r = (*i2).r, S.erase(i2);
            if((*i3).h == tmp.h) tmp.l = (*i3).l, S.erase(i3);
            S.insert(tmp);
        }
    }
    if(S.size() == 1 && (*S.begin()).r == R) {
        cout << "YES ";
        FOR(i, 1, n) cout << len[i] << ' ';
        cout << '\n';
        return 1;
    }
    return 0;
}

IL bool pd() {
    sort(a + 1, a + n + 1, [&](node A, node B){return (A.y != B.y ? A.y < B.y : A.x > B.x);});
    int l = 0, r = 0;
    FOR(i, 1, n) if(a[i].y == 0) l = max(l, a[i].x);
    FOR(i, 1, n) r = max(r, a[i].x);
    FOR(i, 1, n) if(a[i].y != 0 && l + a[i].y >= r + 1 && chk(l + a[i].y - 1)) return 1;
    return 0;
}

IL void solve() {
    cin >> n; int mx = inf, my = inf;
    FOR(i, 1, n) cin >> a[i].x >> a[i].y, a[i].id = i, mx = min(a[i].x, mx), my = min(a[i].y, my); 
    bool ff = 0;
    FOR(i, 1, n) {
        a[i].x -= mx, a[i].y -= my;
        if(a[i].x == 0 && a[i].y == 0) ff = 1;
    }
    if(!ff) return cout << "NO\n", void();
    if(pd()) return;
    FOR(i, 1, n) swap(a[i].x, a[i].y);
    if(pd()) return;
    cout << "NO\n";
    return;
}

signed main() {
    // freopen("puzzle.in", "r", stdin);
    // freopen("puzzle.out", "w", stdout);
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int TT; cin >> TT;
    while(TT--) solve();
    return 0;
}

/*
    Author: _LiMLE_
    start codint at: 21:09
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5696kb

input:

3
2
0 0
0 1
2
3 2
2 3
4
1 1
2 1
3 1
1 2

output:

YES 1 1 
NO
YES 1 1 1 3 

result:

ok 3 testow OK.

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5636kb

input:

50
21
2 1
0 4
1 3
1 2
0 2
0 1
1 4
2 3
0 3
2 4
0 0
1 1
1 0
0 6
1 5
2 0
2 2
2 5
1 6
2 6
0 5
1
3 17
9
3 17
28 12
27 3
17 3
17 13
27 12
21 13
3 3
21 20
9
68 38
75 22
34 47
70 50
70 45
59 38
34 22
68 45
59 22
10
47 38
75 35
70 54
64 49
64 38
72 13
72 35
47 55
47 13
70 49
10
54 47
42 111
9 92
42 123
35 11...

output:

YES 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO

result:

wrong answer Test 2: oczekiwano YES, wczytano NO.