QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#760196#5983. Pretty Good ProportionCoding_goat_qwq27 ✓1352ms21788kbC++141.6kb2024-11-18 15:32:362024-11-18 15:32:38

Judging History

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

  • [2024-11-18 15:32:38]
  • 评测
  • 测评结果:27
  • 用时:1352ms
  • 内存:21788kb
  • [2024-11-18 15:32:36]
  • 提交

answer

#include<bits/stdc++.h>

#define mem(a,b) memset((a),(b),sizeof(a))
#define m0(a) memset((a),0,sizeof(a))
#define lb(x) ((x)&-(x))
#define lc(x) ((x)<<1)
#define rc(x) (((x)<<1)|1)
#define pb(G,x) (G).push_back((x))
#define For(a,b,c) for(int a=(b);a<=(c);a++)
#define Rep(a,b,c) for(int a=(b);a>=(c);a--)
#define in1(a) a=read()
#define in2(a,b) a=read(), b=read()
#define in3(a,b,c) a=read(), b=read(), c=read()
#define inn(i,n,a) For(i,1,n) a[i]=read();

#define ll long long
#define i128 __int128

using namespace std;
inline int read() {
	int xx= 0;int f= 1;
	char c = getchar();
	while(c<'0'||c>'9') { 
		if(c=='-') f= -1;
		c= getchar();
	}
	while(c>='0'&&c<='9') {
		xx= (xx<<1)+(xx<<3)+(c^48);
		c= getchar();
	}
	return xx*f;
}
#define maxn 1000050
int n;
long double f;
string s;
pair<long double,int> pre[maxn];
void work() {
	cin>>n>>f>>s; 
	s=' '+s;
	For(i,1,n) {
		pre[i].first=pre[i-1].first+(s[i]-'0')-f;
		pre[i].second=i;
	}
	pre[n+1]={0,0};
	sort(pre+1,pre+n+2);
	long double ans=1e188;
	For(i,1,n) {
		long double x=fabsl((pre[i].first-pre[i+1].first)/(pre[i].second-pre[i+1].second));
		ans=min(ans,x);
	}
	int idx=1e9;
	For(i,1,n) {
		long double x=fabsl((pre[i].first-pre[i+1].first)/(pre[i].second-pre[i+1].second));
		if(fabsl(ans-x)<1e-12) idx=min(idx,min(pre[i].second,pre[i+1].second));
	}
	cout<<idx<<'\n';
	For(i,0,n+1) pre[i].first=pre[i].second=0;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int _;
	cin>>_;
	For(i,1,_) {
		cout<<"Case #"<<i<<": ";
		work();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 4ms
memory: 3964kb

input:

100
10 0.827672
0010101011
4 0.932623
0100
1000 0.834002
011001110010111110000110101100010010100101101110110111100010101101111100110001011000110100010100011011000001100001010110111101111010110110000110011000111000011110101100100111111001111011011100111001011101010100111011100011110011100011110010001...

output:

Case #1: 6
Case #2: 1
Case #3: 10
Case #4: 0
Case #5: 0
Case #6: 1
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 4
Case #13: 5
Case #14: 564
Case #15: 0
Case #16: 0
Case #17: 0
Case #18: 0
Case #19: 0
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 844
Case #25: 0
Case...

result:

ok 100 lines

Subtask #2:

score: 22
Accepted

Test #2:

score: 22
Accepted
time: 1352ms
memory: 21788kb

input:

100
15 0.333333
000000000011000
10 0.418754
0101100001
2 0.499999
01
3 0.977951
001
2 0.249999
01
10 0.670229
0111011001
1000 0.500001
001101111110110010110000010010110001110010001101110111010011000010100011011101010110011011011010111110011100011000001000101011100011010100101101111110100101011010111...

output:

Case #1: 6
Case #2: 0
Case #3: 0
Case #4: 2
Case #5: 0
Case #6: 0
Case #7: 0
Case #8: 0
Case #9: 0
Case #10: 0
Case #11: 0
Case #12: 0
Case #13: 0
Case #14: 0
Case #15: 0
Case #16: 4333
Case #17: 0
Case #18: 0
Case #19: 123
Case #20: 0
Case #21: 0
Case #22: 0
Case #23: 0
Case #24: 0
Case #25: 0
Case...

result:

ok 100 lines

Extra Test:

score: 0
Extra Test Passed