QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#186858 | #6886. Simple Set Problem | neko_nyaa | AC ✓ | 1267ms | 81980kb | C++20 | 1.1kb | 2023-09-24 12:43:18 | 2023-09-24 12:43:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve()
{
int k;
cin >> k;
vector<pair<int, int>> p;
for (int i = 0; i < k; i++)
{
int x;
cin >> x;
while (x--)
{
int v;
cin >> v;
p.emplace_back(v, i);
}
}
sort(p.begin(), p.end());
int n = p.size();
int sz = 0;
map<int, int> cnt;
int r = 0;
int ans = 1e18;
for (int l = 0; l < n; l++)
{
while (r < n && sz < k)
{
cnt[p[r].second]++;
if (cnt[p[r].second] == 1)
sz++;
r++;
}
if (sz < k)
break;
ans = min(ans, p[r - 1].first - p[l].first);
cnt[p[l].second]--;
if (cnt[p[l].second] == 0)
sz--;
}
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1267ms
memory: 81980kb
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