QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752910 | #5983. Pretty Good Proportion | PengAo | 27 ✓ | 1290ms | 30852kb | C++14 | 3.3kb | 2024-11-16 10:24:42 | 2024-11-16 10:24:42 |
Judging History
answer
/*
* @Author: Linmobi & TLE_Automaton & ChinoKafuu
* @Date: 2024-11-16 09:46:24
* @LastEditors: Linmobi
* @LastEditTime: 2024-11-16 10:18:27
* @FilePath: /A.cpp
* @Description: Right Output ! & Accepted !
*/
#include<bits/stdc++.h>
// #define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
#define rep(i, a, b) for(int i = (a);i <= (b);i++)
#define per(i, a, b) for(int i = (a);i >= (b);i--)
#define rp(i, a) for(int i = 1; i <= (a); i++)
#define pr(i, a) for(int i = (a); i >= 1; i--)
#define go(i, x) for(auto i : x)
#define lowbit(x) (x & (-x))
#define mp make_pair
#define pb push_back
#define gc getchar
#define fir first
#define sec second
using namespace std;
const int P = 1e9 + 7, L = 1e6 + 5, inf = 2e9 + 5;
inline ll qpow(ll a, ll b) { ll ans = 1, q = a; while(b) { if(b & 1) { ans *= q; ans %= P; } q *= q; q %= P; b >>= 1; } return ans; }
inline ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
inline ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
namespace fast_IO {
template<typename T> inline void rd(T &x) {
x = 0; bool f = 0; char ch = getchar();
while (! isdigit(ch)) f |= (ch == '-'), ch = getchar();
while (isdigit(ch)) x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
x = (f ? - x : x);
}
template<typename T, typename... Args> inline void rd(T &first, Args& ... args) {
rd(first);
rd(args...);
}
template<typename T> inline void write(T x, bool f) {
if (x < 0) x = -x, putchar('-'); static short Stack[50], top(0);
do Stack[++ top] = x % 10, x /= 10; while (x);
while (top) putchar(Stack[top --] | 48);
(f ? putchar('\n') : putchar(' '));
}
} using namespace fast_IO;
namespace fenwick {
int t[L];
void add(int w, int num) {
while(w < L) t[w] += num, w += lowbit(w);
}
int query(int w) {
int sum = 0;
while(w) sum += t[w], w -= lowbit(w);
return sum;
}
}
/***************************************************************************************************************************/
/* */
/***************************************************************************************************************************/
long double f[L];
int n;
char s[L];
long double e;
pair<long double, int> k[L];
int T;
signed main() {
rd(T); rep(_, 1, T) {
rd(n);
scanf("%Lf", &e);
scanf("%s", s + 1);
// n = strlen(s + 1);
rep(i, 1, n)
f[i] = s[i] -'0', f[i] -= e;
rep(i, 1, n) k[i] = {f[i] + k[i - 1].fir, i};
k[n + 1] = {0, 0};
long double der = inf;
sort(k + 1, k + 2 + n);
rep(i, 1, n) {
der = min(der, abs((k[i + 1].fir - k[i].fir) / (k[i + 1].sec - k[i].sec)));
}
// cerr << der << endl;
int ans = n + 1;
const long double eps = 1e-12;
rep(i, 1, n) {
if(abs(der - abs((k[i + 1].fir - k[i].fir) / (k[i + 1].sec - k[i].sec))) < eps) {
ans = min(ans, min(k[i].sec, k[i + 1].sec));
}
}
cout << "Case #" << _ << ": "<< ans << endl;
}
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 8020kb
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: 1290ms
memory: 30852kb
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