# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
702646 |
2023-02-24T16:37:19 Z |
victor_gao |
Naan (JOI19_naan) |
C++17 |
|
2 ms |
340 KB |
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC optimize("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//#pragma pack(1)
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define int long long
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
//using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> order_multiset;
//typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> order_set;
int n,l,v[10][2015],total[10];
pii add(pii a,pii b){
int up=(a.x*b.y+a.y*b.x);
int down=(a.y*b.y);
if (up==0||down==0)
return {up,down};
int g=__gcd(up,down);
return {up/g,down/g};
}
pii sub(pii a,pii b){
int up=(a.x*b.y-a.y*b.x);
int down=(a.y*b.y);
if (up==0||down==0)
return {up,down};
int g=__gcd(up,down);
return {up/g,down/g};
}
pii mul(pii a,pii b){
int up=a.x*b.x;
int down=a.y*b.y;
if (up==0||down==0)
return {up,down};
int g=__gcd(up,down);
return {up/g,down/g};
}
bool bigger(pii a,pii b){
return a.x*b.y>=a.y*b.x;
}
signed main(){
fast
cin>>n>>l;
for (int i=1;i<=n;i++){
for (int j=1;j<=l;j++){
cin>>v[i][j];
total[i]+=v[i][j];
}
}
int sum=0,p=0;
pii ans1,ans2={0,1};
for (int i=1;i<=l;i++){
if ((sum+v[1][i])*n>=total[1]){
p=i;
ans1={(total[1]-sum*n),n*v[1][i]};
pii last=sub({1,1},ans1);
ans2=add(ans2,{last.x*v[2][i],last.y});
break;
}
else sum+=v[1][i];
}
for (int i=p+1;i<=l;i++)
ans2=add(ans2,{v[2][i],1});
if (bigger(ans2,{total[2],n})){
pii pos=add({p-1,1},ans1);
cout<<pos.x<<' '<<pos.y<<'\n';
cout<<1<<" "<<2<<'\n';
}
else {
ans1={0,1}; ans2={0,1};
p=0; sum=0;
for (int i=1;i<=l;i++){
if (bigger(mul(add(ans2,{v[2][i],1}),{n,1}),{total[2],1})){
p=i;
ans2={(total[2]-ans2.x*n),n*v[2][i]};
pii last=sub({1,1},ans2);
ans1=add(ans1,{last.x*v[1][i],last.y});
break;
}
else ans2=add(ans2,{v[2][i],1});
}
for (int i=p+1;i<=l;i++)
ans1=add(ans1,{v[1][i],1});
if (bigger(ans1,{total[1],n})){
pii pos=add({p-1,1},ans2);
cout<<pos.x<<" "<<pos.y<<"\n2 1\n";
}
else cout<<-1<<'\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
X_i is not increasing |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
2 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Incorrect |
1 ms |
340 KB |
X_i is not increasing |
18 |
Halted |
0 ms |
0 KB |
- |