QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36796#2442. Welcome PartyafhiWA 419ms9816kbC++2.4kb2022-06-28 20:28:502022-06-28 20:28:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-28 20:28:52]
  • 评测
  • 测评结果:WA
  • 用时:419ms
  • 内存:9816kb
  • [2022-06-28 20:28:50]
  • 提交

answer

#include <cassert>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <complex>
#include <list>
#include <vector>
#include <array>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <random>

#ifdef AFHI
#include "debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ["; _print(##__VA_ARGS__)
#else
#define debug(...)
#endif

#define SZ(x) (int) x.size()

using ll = long long;
template<typename T> using V = std::vector<T>;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }

void solve() {
    int n;
    std::cin>>n;
    V<ll> x(n),y(n);
    for (int i = 0;i < n;i++) {
        std::cin>>x[i]>>y[i];
    }
    V<int> order(n);
    std::iota(order.begin(),order.end(),0);
    std::sort(order.begin(),order.end(),[&] (int i,int j) {
        return x[i] > x[j];
    });
    ll ans = ll(2e18);
    ll max_y = 0;

    for (int i = 0,j;i < n;i = j) {
        j = i;
        while (j < n && x[order[j]] == x[order[i]]) {
            j++;
        }
        if (max_y != 0) {
            for (int k = i;k < j;k++) {
                ckmin(ans,std::abs(max_y - x[order[k]]));
            }
        }
        for (int k = i;k < j;k++) {
            ckmax(max_y,y[order[k]]);
        }
    }

    std::multiset<ll> xs;
    for (int i = 0;i < n;i++) {
        if (x[order[i]] != x[order[0]]) break;
        xs.insert(x[order[i]]);
    }
    for (int i = 0;i < n;i++) {
        if (x[i] == x[order[0]]) {
            xs.erase(xs.find(x[i]));
        }
        auto it = xs.lower_bound(y[i]);
        if (it != xs.end()) {
            debug(y[i],*it);
            ckmin(ans,*it - y[i]);
        }
        if (it != xs.begin()) {
            ckmin(ans,y[i] - *(std::prev(it)));
        }
        if (x[i] == x[order[0]]) {
            xs.insert(x[i]);
        }
    }
    std::cout<<ans<<'\n';
}

int main() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout<<std::fixed<<std::setprecision(10);
    int t;
    std::cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 419ms
memory: 9816kb

input:

66
5
27 46
89 13
55 8
71 86
22 35
3
3 5
4 7
6 2
2
0 1000000000
1000000000 0
2
1000000000 0
0 1000000000
2
1000000000 0
1000000000 0
2
0 1000000000
0 1000000000
2
1000000000 1000000000
0 0
2
0 0
0 0
2
1000000000 1000000000
1000000000 1000000000
3
90 30
90 50
90 85
3
0 0
0 2
0 5
3
20 30
20 50
20 70
3
...

output:

3
1
0
0
1000000000
1000000000
1000000000
0
0
5
0
10
5
10
3
0
10
5
0
5
5
10
5
10
3
0
10
5
0
146595730144168239
10974087366700578
21076180420813408
183538167814754058
87358691998303367
365292306661444331
23639646046527434
40476687889457528
270663364266559542
139940820548070767
21494649603533736
100200...

result:

wrong answer 21st lines differ - expected: '0', found: '5'