QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#196344 | #6886. Simple Set Problem | Royo# | WA | 1124ms | 106580kb | C++20 | 2.1kb | 2023-10-01 16:07:22 | 2023-10-01 16:07:23 |
Judging History
answer
#include <bits/stdc++.h>
#include <cstdio>
#define int long long
#define PII pair<int, int>
#pragma GCC optimize("Ofast")
#define NO {puts("No") ; return ;}
#define YES {puts("Yes") ; return ;}
#define pb push_back
#define endl "\n"
#define fi first
#define se second
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
using namespace std;
mt19937 rd(time(0));
const int N = 1e5 + 10;
void solve() {
int n; cin >> n;
vector<vector<int>> a(n);
for (int i = 0; i < n; i ++ ) {
int m; cin >> m;
for (int j = 0; j < m; j ++ ) {
int x; cin >> x;
a[i].pb(x);
}
sort(a[i].begin(), a[i].end());
}
if (n == 1) {
cout << 0 << endl;
return ;
}
int ans = LONG_LONG_MAX;
for (int i = 0; i < a[0].size(); i ++ ) {
int c = a[0][i];
vector<int> b, d, e, f;
b.pb(c);
d.pb(c);
e.pb(c);
f.pb(c);
for (int j = 1; j < n; j ++ ) {
int l = -1, r = a[j].size();
while (l + 1 != r) {
int mid = l + r >> 1;
if (a[j][mid] >= c) r = mid;
else l = mid;
}
int ll = -1, rr = a[j].size();
while (ll + 1 != rr) {
int mid = ll + rr >> 1;
if (a[j][mid] <= c) ll = mid;
else rr = mid;
}
if (r != a[j].size() && ll != -1) {
if (abs(c - a[j][r]) != abs(c - a[j][ll])) {
if (abs(c - a[j][r]) > abs(c - a[j][ll]))
b.pb(a[j][ll]), d.pb(a[j][ll]);
else
b.pb(a[j][r]), d.pb(a[j][r]);
} else {
b.pb(a[j][ll]);
d.pb(a[j][r]);
}
e.pb(a[j][ll]);
f.pb(a[j][r]);
} else if (r != a[j].size()) {
b.pb(a[j][r]);
d.pb(a[j][r]);
f.pb(a[j][r]);
e.pb(a[j][r]);
} else if (ll != -1) {
b.pb(a[j][ll]);
d.pb(a[j][ll]);
e.pb(a[j][ll]);
f.pb(a[j][ll]);
}
}
sort(b.begin(), b.end());
sort(d.begin(), d.end());
sort(e.begin(), e.end());
sort(f.begin(), f.end());
ans = min(min(ans, e.back() - e[0]), f.back() - f[0]);
ans = min(min(ans, d.back() - d[0]), b.back() - b[0]);
}
cout << ans << endl;
}
signed main() {
IOS;
int t; cin >> t;
while (t -- )
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1124ms
memory: 106580kb
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:
wrong answer 60th lines differ - expected: '732645649', found: '797312924'