QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#581610#9381. 502 Bad GatewaybiaobenplusWA 547ms5696kbC++171.8kb2024-09-22 13:35:312024-09-22 13:35:33

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 14:55:37]
  • hack成功,自动添加数据
  • (/hack/886)
  • [2024-09-22 13:35:33]
  • 评测
  • 测评结果:WA
  • 用时:547ms
  • 内存:5696kb
  • [2024-09-22 13:35:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
#define int long long
const int INF = 4e18+5;
#define F(i,l,r) for(int i=l;i<=r;i++)
#define R(i,l,r) for(int i=r;i>=l;i--)
#define vv vector
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
//const int mod = 998244353; 
const int mod = 1e9+7; 
const int M = 1e7+5;
int b[N],dp[N],vis[N],pri[N],a[N],ans1[N],ans2[N],c[N]; 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,k,ans,x,y,n0,n2,m0,m2,op,op1,op2;
string s;
map<int,int>mp;
map<int,int>mmap;
//char mp[1005][1005];
//vector<int>v1[N],v2[N];
int lowbit(int x) {
	return x&-x;
}
char xx[N];
bool temp;
int kuai(int x,int y){
	int sum=1;
	x%=mod;
	while(y){
		if(y%2){
			y--;
			sum*=x;
			sum%=mod;
		  }
	  x*=x;
	  y/=2;
	  x%=mod;
	}
	return sum;
}
struct node{
	int sum,l,r,add;
}tree[N];
bool check(int x){
	int x0,y0,x1=(1+n)*n,y1=2;
	y=x-1;
	x0=(1+x)*x/2+(n-x);
	y0=x;
	if(y>0){
		x1=(1+y)*y/2+(n-y);
		y1=y;
	}
	//cout<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<endl;
	if(x0*y1<=x1*y0) {
		op1=x0,op2=y0;
		return true;
	}
	return false;
}
void solve()
{
	cin>>n;
	int l=1,r=n+1;
	op1=(1+n)*n/2; op2=n;
    while(l<r){
    	int mid=l+r>>1;
    	//cout<<mid<<"**"<<endl;
    	if(check(mid)) l=mid+1;
    	else r=mid;
	}
	op=__gcd(op1,op2);
	cout<<op1/op<<" "<<op2/op<<endl;
}
signed main() 
{
	ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0); // cin.tie(nullptr);
    int T = 1;                                                                                                                                                                                                                                                                    
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5696kb

input:

3
1
2
3

output:

1 1
3 2
2 1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 295ms
memory: 5644kb

input:

1000000
1
1000000000
1
1
1000000000
1
1000000000
1
1
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1
1
1000000000
1
1000000000
1000000000
1
1000000000
1000000000
1000000000
1000000000
1000000000
1000000000
1
1
1000000000
1
1000000000
1000000000
1000000000
1000000000
1
1
1
10000000...

output:

1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1 1
1 1
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1 1
1999961560 44721
1999961560 44721
1999961560 44721
19...

result:

ok 1000000 lines

Test #3:

score: -100
Wrong Answer
time: 547ms
memory: 5664kb

input:

1000000
158260522
877914575
602436426
24979445
861648772
623690081
433933447
476190629
262703497
211047202
971407775
628894325
731963982
822804784
450968417
430302156
982631932
161735902
880895728
923078537
707723857
189330739
910286918
802329211
404539679
303238506
317063340
492686568
773361868
125...

output:

316511467 17791
1755824328 41903
1204845831 34711
49954223 7068
1723292600 41513
623676492 17659
867864517 29460
952375859 30861
262700539 11461
422085442 20545
1942776701 44077
251551941 7093
1463896912 38261
1645584679 40566
901913913 30032
107573492 3667
1965228547 44331
323457022 17985
176178307...

result:

wrong answer 41st lines differ - expected: '1908546898 43687', found: '113834095639060138 477145879'