Submission #375174

#TimeUsernameProblemLanguageResultExecution timeMemory
375174wiwihoNaan (JOI19_naan)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define eb emplace_back #define iter(a) a.begin(), a.end() #define printv(a, b) { \ for(auto pv : a) b << pv << " "; \ b << "\n"; \ } #define mp make_pair #define F first #define S second using namespace std; typedef long long ll; using pll = pair<ll, ll>; struct frac{ ll a, b; frac(ll a = 0, ll b = 1): a(a), b(b) { } void qaq(){ if(b < 0) b *= -1, a *= -1; ll g = __gcd(a, b); a /= g; b /= g; } }; frac operator+(frac f1, frac f2){ ll g = __gcd(f1.b, f2.b); return frac(f1.a * (f2.b / g) + f2.a * (f1.b / g), f1.b * f2.b / g); } frac operator*(frac f1, frac f2){ return frac(f1.a * f2.a, f1.b * f2.b); } frac operator/(frac f1, frac f2){ return f1 * frac(f2.b, f2.a); } frac operator-(frac f1, frac f2){ return f1 + frac(-f2.a, f2.b); } frac operator+=(frac& f1, frac f2){ f1 = f1 + f2; } frac operator-=(frac& f1, frac f2){ f1 = f1 - f2; } bool operator<=(frac f1, frac f2){ ll g = __gcd(f1.b, f2.b); return f1.a * (f2.b / g) <= f2.a * (f1.b / g); } bool operator==(frac f1, frac f2){ f1.qaq(); f2.qaq(); return f1.a == f2.a && f1.b == f2.b; } ostream& operator<<(ostream& o, frac f){ return o << f.a << '/' << f.b; } int n, l; vector<vector<int>> v; vector<frac> check(vector<int>& p){ //cerr << "test "; //printv(p, cerr); int lst = 0; frac r(1); vector<frac> ans; for(int i : p){ frac total = 0; for(int j = 0; j < l; j++) total += v[i][j]; frac need = total / n; while(need.a != 0 && lst < l){ //cerr << i << " " << lst << " " << r << " " << need << "\n"; if(r.a == 0){ r = 1; lst++; continue; } if(v[i][lst] * r <= need){ //cerr << "test1 " << v[i][lst] * r << "\n"; need -= v[i][lst] * r; r = 1; lst++; continue; } r -= need / v[i][lst]; need = 0; } if(need == 0){ //cerr << "ok " << frac(lst) + 1 - r << "\n"; if(i != p.back()) ans.eb(frac(lst) + 1 - r); else ans.eb(l); } else return vector<frac>(); } return ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> l; v.resize(n + 1, vector<int>(l)); vector<int> p(n); for(int i = 1; i <= n; i++){ p[i - 1] = i; for(int j = 0; j < l; j++) cin >> v[i][j]; } return 0; do{ vector<frac> ans = check(p); if(ans.empty()) continue; for(int j = 0; j < n - 1; j++){ frac i = ans[j]; cout << i.a << " " << i.b << "\n"; } printv(p, cout); return 0; } while(next_permutation(iter(p))); cout << "-1\n"; return 0; }

Compilation message (stderr)

naan.cpp: In function 'frac operator+=(frac&, frac)':
naan.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
   45 | }
      | ^
naan.cpp: In function 'frac operator-=(frac&, frac)':
naan.cpp:48:1: warning: no return statement in function returning non-void [-Wreturn-type]
   48 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...