# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
375192 |
2021-03-09T04:12:24 Z |
wiwiho |
Naan (JOI19_naan) |
C++14 |
|
1 ms |
364 KB |
#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);
if(g == 0){
cout << "QAQ\n";
exit(0);
}
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 = frac(0, 1);
for(int j = 0; j < l; j++){
total = total + frac(v[i][j], 1);
}
/*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";
ans.eb(frac(lst) + 1 - r);
}
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];
}
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
naan.cpp: In function 'frac operator+=(frac&, frac)':
naan.cpp:49:1: warning: no return statement in function returning non-void [-Wreturn-type]
49 | }
| ^
naan.cpp: In function 'frac operator-=(frac&, frac)':
naan.cpp:52:1: warning: no return statement in function returning non-void [-Wreturn-type]
52 | }
| ^
naan.cpp: In function 'std::vector<frac> check(std::vector<int>&)':
naan.cpp:73:9: warning: unused variable 'lst' [-Wunused-variable]
73 | int lst = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
364 KB |
Integer parameter [name=A_i] equals to -1, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |