QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687347 | #6472. Robots | LaVuna47# | AC ✓ | 1ms | 4116kb | C++20 | 1.9kb | 2024-10-29 18:31:40 | 2024-10-29 18:31:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<db, db> pdd;
#ifdef ONPC
mt19937 rnd(228);
#endif
int solve()
{
int n;
if (!(cin >> n))
return 1;
vector<pll> a(n);
FOR (i, 0, n)
cin >> a[i].x >> a[i].y;
ll base = 0, best = 0;
ll ac = 0;
FOR (i, 0, n)
{
ll st = ac + a[i].x;
ll en = st + a[i].x * (a[i].y - 1);
//cerr << "st = " << st << " en = " << en << '\n';
assert(((st + en) * a[i].y) % 2 == 0);
ll curr = (st + en) * a[i].y / 2;
//cerr << "ac = " << ac;
//cerr << " curr = " << curr << '\n';
base += curr;
ac += a[i].x * a[i].y;
}
//cerr << "base = " << base << '\n';
sort(rall(a));
ac = 0;
FOR (i, 0, n)
{
ll st = ac + a[i].x;
ll en = st + a[i].x * (a[i].y - 1);
//cerr << "st = " << st << " en = " << en << '\n';
assert(((st + en) * a[i].y) % 2 == 0);
ll curr = (st + en) * a[i].y / 2;
//cerr << "ac = " << ac;
//cerr << " curr = " << curr << '\n';
best += curr;
ac += a[i].x * a[i].y;
}
//cerr << "best = " << best << '\n';
ll ans = best - base;
cout << fixed << setprecision(1) << (db)ans << '\n';
return 0;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int TET = 1e9;
//cin >> TET;
for (int i = 1; i <= TET; i++)
{
if (solve())
break;
#ifdef ONPC
cerr << "_________________________________\n";
#endif
}
#ifdef ONPC
cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3800kb
input:
1 10 30000
output:
0.0
result:
ok single line: '0.0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3764kb
input:
2 2 1 30 2
output:
56.0
result:
ok single line: '56.0'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
5 2 5 7 4 12 3 10 1 9 15
output:
1007.0
result:
ok single line: '1007.0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
10 1 10 2 9 3 8 4 7 5 6 6 5 7 4 8 3 9 2 10 1
output:
4158.0
result:
ok single line: '4158.0'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
100 100 100 99 99 98 98 97 97 96 96 95 95 94 94 93 93 92 92 91 91 90 90 89 89 88 88 87 87 86 86 85 85 84 84 83 83 82 82 81 81 80 80 79 79 78 78 77 77 76 76 75 75 74 74 73 73 72 72 71 71 70 70 69 69 68 68 67 67 66 66 65 65 64 64 63 63 62 62 61 61 60 60 59 59 58 58 57 57 56 56 55 55 54 54 53 53 52 52 ...
output:
0.0
result:
ok single line: '0.0'
Test #6:
score: 0
Accepted
time: 1ms
memory: 3772kb
input:
1000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1 2000 1...
output:
0.0
result:
ok single line: '0.0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 3904kb
input:
10000 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 1 2 2 3 3 1 4 2 5 3 6 1 7 2 8 3 9 1 10 2 1 3 2 1 3 2 4 3 5 1 6 2 7 3 8 1 9 2 10 3 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 1 2 2 3 3 1 4 2 5 3 6 1 7 2 8 3 9 1 10 2 1 3 2 1 3 2 4 3 5 1 6 2 7 3 8 1 9 2 10 3 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 1 2 2 3 3 1...
output:
330203937.0
result:
ok single line: '330203937.0'
Test #8:
score: 0
Accepted
time: 1ms
memory: 4116kb
input:
5000 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61 1...
output:
20833332500.0
result:
ok single line: '20833332500.0'
Test #9:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
50 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50
output:
0.0
result:
ok single line: '0.0'