You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
#include<iostream>usingnamespacestd;intmain(){int a, b, c, d, e; cout <<"1 0 0" << endl; cin >> a; cout <<"0 1 0" << endl; cin >> b; cout <<"0 0 1" << endl; cin >> c; cout <<"1 1 1" << endl; cin >> d; cout <<"1 2 3" << endl; cin >> e;if (a + b + c == d) cout << a <<'' << b <<'' << c << endl;elseif (a +2 * b +3 * c == e) cout << a <<'' << b <<'' << c << endl;elseif ((d - b - c) +2 * b +3 * c == e) cout << d - b - c <<'' << b <<'' << c << endl;elseif (a +2 * (d - c - a) +3 * c == e) cout << a <<'' << d - c - a <<'' << c << endl;else cout << a <<'' << b <<'' << d - a - b << endl;}
Problem B : Schedule
Solution
#include<algorithm>#include<iostream>#include<vector>usingnamespacestd;intmain() {int N, W;while (cin >> N >> W) {int c; vector<vector<int>> sch;for (c =4; c <= W; c++) { sch.clear(); vector<int>cur(c,1);for (int i = c/2; i < c; i++) cur[i] =2;do { sch.push_back(cur);next_permutation(cur.begin(), cur.end()); }while (cur[0] ==1);if (sch.size() >= N)break; }if (c > W) { cout <<"infinity" << endl;continue; } cout << c << endl;for (int i =0; i < W; i++) {for (int j =0; j < N; j++) cout << sch[j][i%c]; cout << endl; } }}
#include<iomanip>#include<iostream>usingnamespacestd;intmain() {int n, m;while (cin >> n >> m) {int a, tot =0;for (int i =0; i < n*m; i++) { cin >> a; tot += a; } cout << fixed <<setprecision(9) << (longdouble)(tot) / (n*m) << endl; }return0;}
Problem J : Bridging The Gap
Solution :
#include<algorithm>#include<iostream>#include<vector>usingnamespacestd;intmain() {int64_t N, C;while (cin >> N >> C) { vector<int64_t>T(N);for (auto& x : T) cin >> x;sort(T.begin(), T.end()); vector<int64_t>tot(N+1,1e18),cc(N,1e18); tot[0] = cc[0] =0;for (int64_t i =0; i < N; i++) tot[i+1] = tot[i] + T[i];for (int64_t i =1; i < C && i < N; i++) {for (int64_t j = i; j < cc.size(); j++) cc[j] =min(cc[j], cc[j-i] + T[i] + tot[i+1]); }//for (int i = 0; i < N; i++) cerr << "cc[" << i << "] = " << cc[i] << endl; vector<int64_t>mnc(N+1),mxc(N+1); vector<vector<int64_t>>dyn(N+1);for (int64_t i =0; i <= N; i++) mnc[i] = -(i/C) - (i==N);for (int64_t i =0; i <= N; i++) mxc[i] = (N-i+C-1)/C-1;for (int64_t i =0; i <= N; i++) dyn[i].resize(mxc[i]-mnc[i]+1,1e18); dyn[0][0] =0;for (int64_t i =0; i < N; i++)for (int64_t ci =0; ci < dyn[i].size(); ci++) {if (ci && dyn[i][ci] - dyn[i][0] >= cc[ci])continue;int64_t c = mnc[i]+ci;for (int64_t j =min(N, i+C), extra = -1; j > i; j--, extra++) {int64_t c2 = c + extra;if (c2 > mxc[j])break; dyn[j][c2-mnc[j]] =min(dyn[j][c2-mnc[j]], dyn[i][ci] + T[N-1-i] + tot[extra+1]); } }int64_t ret =1e18;for (int64_t c = mnc[N]; c <= -1; c++) ret =min(ret, dyn[N][c-mnc[N]] + cc[-1-c]); cout << ret << endl; }}
Problem K : Alea Lacta Est
Solution :
#include<algorithm>#include<cmath>#include<functional>#include<iomanip>#include<iostream>#include<map>#include<queue>#include<string>#include<vector>usingnamespacestd;intmain() {int N, W;while (cin >> N >> W) { vector<string>D(N);for (auto& d : D) cin >> d; map<string, vector<int>> dw; function<void(int,int,string)> doit = [&](int d,int b, string s) {if (d == N) {sort(s.begin(), s.end()); dw[s].push_back(b);return; }for (int i =0; i < D[d].size(); i++)doit(d+1, b + ((i+1)<<(3*d)), s+D[d][i]); };doit(0,0,""); vector<int>curn(1<<(3*N)),seen(1<<(3*N)); vector<double>cure(1<<(3*N)),beste(1<<(3*N),1e9); priority_queue<pair<double,int>> q;// For a solved full configuration, adjust the expected values of partial configurations that may roll it. function<void(int,int,int,double)> sete = [&](int d,int pw,int b,double e) {if (d == N) {if (pw ==1)return; curn[b]++; cure[b] += e;// We know that be = 1 + ((pw-curn) / pw) * be + (curn / pw) * (cure/curn).double be = (pw + cure[b]) / curn[b]; beste[b] = be; q.push({-be, b});return; }sete(d+1, pw, b, e);sete(d+1, pw*D[d].size(), b & ~(7<<(3*d)), e); };// For a solved partial configuration, any unsolved full configurations that can reach it are now solved. function<void(int,int,double)> brec = [&](int d,int b,double e) {if (d == N) {if (!seen[b])sete(0,1, b, e); seen[b] =true;return; }if (b&(7<<(3*d))) {brec(d+1, b, e); }else {for (int i =0; i < D[d].size(); i++)brec(d+1, b + ((i+1)<<(3*d)), e); } };for (int i =0; i < W; i++) { string w; cin >> w;sort(w.begin(), w.end());for (auto b : dw[w])brec(0, b,0.0); }if (q.empty()) { cout <<"impossible" << endl;continue; }while (!q.empty()) {auto [e, b] = q.top(); q.pop(); e = -e;if (seen[b])continue; seen[b] =true;//for (int d = 0; d < N; d++) if (b&(7<<(3*d))) cout << D[d][((b>>(3*d))&7)-1]; else cout << '.';//cout << ": " << e << endl;// Configuration b is now solved.brec(0, b, e); } cout << fixed <<setprecision(9) << beste[0] << endl; }}
About
🤖 Competitive 🤡 Programming ✈ Algorithms 🛬 Problem 🚀 Solving 🛸 Welcome 🚟 to the ICPC 🚠 International 🚃 Collegiate 🚝 Programming 🚁 Contest ⛴ complete 🏦 problem 🏠 solving 🕌 algorithmic 🍔 techniques 🍞 contest 🍅 preparation 🫑 team ⚽ training ⚾ competitive 🥎 programmers 🏐 who 🏀 want 🏉 to 🎮 perfect ⛸ their 🕹 logic 🧵 speed accuracy