This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// #define int ll
using db = long double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define f first
#define s second
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT, size_t SZ > using AR = array<T, SZ>;
using vi = V<int>;
using vb = V<bool>;
using vl = V<ll>;
using vd = V<db>;
using vs = V<str>;
using vpi = V<pi>;
using vpl = V<pl>;
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define pb push_back
#define yes cout << "Y" << "E" << "S\n";
#define no cout << "N" << "O\n";
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = ((b)-1); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define rep(a) F0R(_,a)
#define each(a,x) for (auto& a: x)
const ll MOD = 1e9 + 7;
const ll MX = 1e9;
const ll INF = 1e18;
const db PI = acos((db)-1);
const int ddef[4]{ 1,0,-1,0 }, dataq[4]{ 0,1,0,-1 };
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
void setIO(string name = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(name)) {
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
}
void _print(char i) { cerr << i; }
void _print(string i) { cerr << i; }
void _print(float i) { cerr << i; }
void _print(int i) { cerr << i; }
void _print(double i) { cerr << i; }
void _print() { cerr << "\n"; };
template<typename x, typename y> void _print(pair<x, y>& t) { cerr << "{";_print(t.first);cerr << ", ";_print(t.second);cerr << "},"; }
template<typename x> void _print(x& t) { cerr << "{"; for (int i = 0;i < (int)t.size();i++) { _print(t[i]); if (i < (int)t.size() - 1) cerr << ", "; } cerr << "}"; }
template<typename x, typename... y> void _print(x a, y... b) { _print(a);if (sizeof...(b)) cerr << ", ";_print(b...); }
#define dbg(x...) cerr<<"["<<#x<<"] = [";_print(x);cerr<<"]\n";
int test;
/*
n bookmarkers
ai and bi outcomes
*/
struct odd{
vi d;
odd(){
d = vi(5, 0);
}
};
bool cmp(const odd& x, const odd& y){
if(x.d[0] == y.d[0]){
if(x.d[1] == y.d[1]){
if(x.d[2] == y.d[2]){
if(x.d[3] == y.d[3]){
if(x.d[4] == y.d[4]){
return 1;
}
return x.d[4] >= y.d[4];
}
return x.d[3] >= y.d[3];
}
return x.d[2] >= y.d[2];
}
return x.d[1] >= y.d[1];
}
return x.d[0] >= y.d[0];
}
void solve() {
int n; cin >> n;
vector<odd> v1;
vector<odd> v2;
F0R(i, n){
str s; cin >> s;
// cout << s << "\n";
bool dot = 0;
int d = 0;
F0R(j, sz(s)){
if(dot) d++;
if(s[j] == '.') dot = 1;
}
odd x;
if(!dot){
s += '.';
}
while(d < 4){
d++;
s += '0';
}
int k = 1;
str t = "";
dot = 0;
F0R(j, sz(s)){
if(s[j] == '.'){
x.d[0] = stoi(t);
dot = 1;
continue;
}
if(dot){
x.d[k] = s[j] - '0';
k++;
}
else{
t += s[j];
}
}
v1.pb(x);
cin >> s;
dot = 0;
d = 0;
F0R(j, sz(s)){
if(dot) d++;
if(s[j] == '.') dot = 1;
}
if(!dot){
s += '.';
}
while(d < 4){
d++;
s += '0';
}
k = 1;
t = "";
dot = 0;
F0R(j, sz(s)){
if(s[j] == '.'){
x.d[0] = stoi(t);
dot = 1;
continue;
}
if(dot){
x.d[k] = s[j] - '0';
k++;
}
else{
t += s[j];
}
}
v2.pb(x);
}
sort(all(v1), cmp);
sort(all(v2), cmp);
vector<odd> p1;
vector<odd> p2;
odd temp1;
F0R(i, n + 1){
p1.pb(temp1);
if(i == n) break;
F0R(j, 5){
temp1.d[j] += v1[i].d[j];
}
}
odd temp2;
F0R(i, n + 1){
p2.pb(temp2);
if(i == n) break;
F0R(j, 5) temp2.d[j] += v2[i].d[j];
}
odd ans;
F0R(i, n + 1){
F0R(j, n + 1){
int cur = i + j;
odd x, y;
F0R(k, 5){
x.d[k] += p1[i].d[k];
y.d[k] += p2[j].d[k];
}
for(int k = 4; k; k--){
int v = x.d[k] / 10;
x.d[k] -= v * 10;
x.d[k - 1] += v;
v = y.d[k] / 10;
y.d[k] -= v * 10;
y.d[k - 1] += v;
}
// cout << cur << "\n";
// F0R(k, 5){
// cout << x.d[k] << " ";
// }
// cout << "\n";
// F0R(k, 5){
// cout << y.d[k] << " ";
// }
// cout << "\n";
x.d[0] -= cur;
y.d[0] -= cur;
vector<odd> temp;
temp.pb(x);
temp.pb(y);
sort(all(temp), cmp);
vector<odd> other_temp;
other_temp.pb(temp[1]);
other_temp.pb(ans);
sort(all(other_temp), cmp);
ans = other_temp[0];
}
}
cout << ans.d[0] << ".";
FOR(i, 1, 5) cout << ans.d[i];
}
signed main() {
setIO("");
int T = 1;
// cin >> T;
for (test = 1; test <= T; test++) solve();
}
Compilation message (stderr)
sure.cpp: In function 'void setIO(std::string)':
sure.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
52 | freopen((name + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sure.cpp:53:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
53 | freopen((name + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |