//#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][10],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';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Integer parameter [name=A_i] equals to 0, violates the range [1, 2000000000000] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Runtime error |
1 ms |
468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |