QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#212656#6823. Coffee Overdosejiangtaizhe001WA 6ms4376kbC++141.6kb2023-10-13 19:09:152023-10-13 19:09:15

Judging History

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

  • [2024-04-08 20:49:53]
  • hack成功,自动添加数据
  • (/hack/589)
  • [2023-10-13 19:09:15]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:4376kb
  • [2023-10-13 19:09:15]
  • 提交

answer

#include<cstdio>
#include<iostream>
#define db double
#define pc putchar
#define ll long long
#define Tp template<typename _T>
Tp _T mabs(_T a){ return a<0?-a:a; }
Tp _T mmax(_T a,_T b){ return a<b?b:a; }
Tp _T mmin(_T a,_T b){ return a<b?a:b; }
Tp void mswap(_T &a,_T &b){ _T t=a; a=b; b=t; return; }
using namespace std;
struct IO{
	char buf[1<<21],*p1,*p2;
	char gc(){ return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++; }
	IO & operator >> (char &x){ x=gc(); while(x=='\r'||x=='\n'||x==' ') x=gc(); return *this; }
	Tp IO & operator >> (_T &x){
		x=0; char c=gc(); bool f=0; while(c<'0'||c>'9'){ if(c=='-') f^=1; c=gc(); }
		while('0'<=c&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=gc(); f?x=-x:0; return *this;
	}
	int st[39],top;
	IO & operator << (char x) { pc(x); return *this; }
	Tp IO & operator << (_T x){
		if(x<0) x=-x,pc('-'); if(x==0){ pc('0'); return *this; }
		top=0; while(x) st[++top]=x%10,x/=10;
		while(top--) pc(st[top+1]+48); return *this;
	}
}fin;
#define maxn
ll s,c;
ll js(ll x){
	ll k,l,ans;
	ans=x*c;
	k=(mmin(c*(c+1)/2,s)-x)/(c+1);
	l=k*(c+1)+x;
	ans+=(s+l+1)*(s-l)/2;
	ans+=(l+x+c+1)*k/2*c;
	k=(s+c)/(c+1);
	ans=mmax(ans,(s+s-(k-1)*(c+1))*k*c/2);
	return ans;
}
void work(){
	fin>>s>>c; if(c==1){ fin<<s*(s+1)/2<<'\n'; return; }
	if(s<=c){ fin<<c*s<<'\n'; return; }
	int l=1,r=c,lm,rm; ll ans=-1;
	while(l+10<r){
		lm=(l+l+r)/3; rm=(l+r+r)/3;
		if(js(lm)<js(rm)) l=lm; else r=rm;
	}
	while(l<=r) ans=mmax(ans,js(l)),l++;
	fin<<ans<<'\n';
}
int main(){
#ifdef LOCAL
	freopen("1.in","r",stdin);
	//freopen(".out","w",stdout);
#endif
	int T; fin>>T; while(T--) work(); return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3708kb

input:

4
1 2
2 1
10 4
172800 172800

output:

2
3
63
29859840000

result:

ok 4 tokens

Test #2:

score: -100
Wrong Answer
time: 6ms
memory: 4376kb

input:

100000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 ...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

wrong answer 6012th words differ - expected: '157', found: '156'