1 solutions
-
-1
#include <bits/stdc++.h> using namespace std; using ll = long long; struct node { ll cntX; ll sumD; ll score; }; bool cmp(node x, node y) { return x.cntX * y.sumD > y.cntX * x.sumD; } int main() { int n; cin >> n; vector<node>a(n); for (int i = 0; i < n; ++i) { string s; cin >> s; ll cx = 0, sd = 0, cur = 0; for (char c : s) { if (c == 'X') cx++; else { int val = c - '0'; sd += val; cur += 1ll * val * cx; } } a[i] = {cx, sd, cur}; } sort(a.begin(), a.end(), cmp); ll totalscore = 0; ll totalx = 0; for (int i = 0; i < n; ++i) { totalscore += a[i].score; totalscore += a[i].sumD * totalx; totalx += a[i].cntX; } cout << totalscore << endl; return 0; }
Information
- ID
- 24351
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- (None)
- # Submissions
- 201
- Accepted
- 46
- Uploaded By