QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469236#6886. Simple Set Problemgrass8cowAC ✓524ms23424kbC++17685b2024-07-09 16:38:342024-07-09 16:38:34

Judging History

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

  • [2024-07-09 16:38:34]
  • 评测
  • 测评结果:AC
  • 用时:524ms
  • 内存:23424kb
  • [2024-07-09 16:38:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int k;
#define fi first
#define se second
int t[1001000];
void sol(){
    scanf("%d",&k);
    vector<pair<int,int> >o;
    for(int i=1,sz,x;i<=k;i++){
        scanf("%d",&sz);
        while(sz--)scanf("%d",&x),o.push_back({x,i});
    }
    sort(o.begin(),o.end());int sz=o.size();
    for(int i=1;i<=k;i++)t[i]=0;
    int ans=2e9+7;
    for(int i=0,j=0,ps=0;i<sz;i++){
        if(!t[o[i].se])ps++;
        t[o[i].se]++;
        while(t[o[j].se]>1)t[o[j].se]--,j++;
        if(ps==k)ans=min(ans,o[i].fi-o[j].fi);
    }
    printf("%d\n",ans);
}
int main(){
    int T;scanf("%d",&T);while(T--)sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 524ms
memory: 23424kb

input:

10018
1
5 -247462786 -97914904 849160785 -951926514 -829935728
7
72 8382969 -3251289 -63130380 -590108505 -798189380 -140833313 -626464256 136468139 -711222365 500861930 -459837972 914918723 186793042 872925162 -335485808 641571163 -314777234 -520573290 -894124702 618889116 2700292 -714868427 -34346...

output:

0
1800402714
860165806
487641037
229279918
238532335
392707612
456994871
256099628
1023121975
4986247
753213024
0
1289600751
598093746
55025093
95257568
145430738
34342513
0
157895624
789721360
232287715
1817496622
439049782
777966568
29118927
1671939338
1048279188
42073227
642353647
61747459
302989...

result:

ok 10018 lines