QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#197406 | #6886. Simple Set Problem | haze | AC ✓ | 385ms | 23232kb | C++23 | 1.3kb | 2023-10-02 15:35:26 | 2023-10-02 15:35:26 |
Judging History
answer
#include<bits/stdc++.h>
#define irep(i,l,r) for(int i = l; i <= r; ++i)
#define drep(i,r,l) for(int i = r; i >= l; --i)
#define ceil(pp,qq) (((pp)>0)^((qq)>0)?-Abs(pp)/Abs(qq):(pp)%(qq)?(pp)/(qq)+1:(pp)/(qq))
#define floor(pp,qq) (((pp)>0)^((qq)>0)?-ceil(abs(pp),abs(qq)):(pp)/(qq))
#define ll long long
using namespace std;
ll Abs(ll x){return x > 0 ? x : - x;}
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
const int itinf = 2e9;
const ll llinf = 4e18;
const int mod = 1000000007;
const int N = 500009;
void solve(){
int n = read(), sum = 0, sz = 0;
vector<array<int,2>> a;
vector<int>cnt(n);
irep(i,0,n-1){
int c = read();
irep(j,0,c-1){
int x = read();
a.push_back({x, i});
}
}
sort(a.begin(), a.end());
sz = a.size();
int l = 0, r = -1;
ll ans = itinf;
while(l < sz){
while(r + 1 < sz && sum < n){
cnt[a[++ r][1]] ++;
if(cnt[a[r][1]] == 1)++ sum;
}
if(sum == n)ans = min(ans, 1ll * a[r][0] - a[l][0]);
cnt[a[l][1]] --;
if(cnt[a[l ++][1]] == 0)-- sum;
}
printf("%lld\n", ans);
}
int main(){
int T = read();
while(T --){
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 385ms
memory: 23232kb
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