QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#858467#4754. BallswanggkAC ✓269ms4608kbC++141.9kb2025-01-16 17:32:202025-01-16 17:32:20

Judging History

This is the latest submission verdict.

  • [2025-01-16 17:32:20]
  • Judged
  • Verdict: AC
  • Time: 269ms
  • Memory: 4608kb
  • [2025-01-16 17:32:20]
  • Submitted

answer

/*
 * @Author: wanggk
 * @Date: 2024-12-31 16:15:16
 * No surrender, no illusions
 * And for better or worse
 */
#include<bits/stdc++.h>
#define Spc putchar(' ')
#define End putchar('\n')
#define For(i,il,ir) for(int i=(il);i<=(ir);++i)
#define Fr(i,il,ir) for(int i=(il);i<(ir);++i)
#define Forr(i,ir,il) for(int i=(ir);i>=(il);--i)
#define ForE(u) for(int i=head[u];~i;i=e[i].nxt)
#define fi first
#define se second
#define mk make_pair
#define pb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
namespace _TvT_{
    template<typename T>
    inline void rd(T& x){
        bool f=0;x=0;char ch=getchar();
        while(ch<'0'||ch>'9'){ if(ch=='-') f=1; ch=getchar(); }
        while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
        if(f) x=-x;
    }
    template<typename T,typename... Args>
    void rd(T& first,Args&... args){ rd(first),rd(args...); }
    int write_num[50];
    template<typename T>
    inline void write(T x){
        int len=0;
        if(x<0) putchar('-'),x=-x;
        do write_num[len++]=x%10ll; while(x/=10ll);
        while(len--) putchar(write_num[len]+'0');
    }
    template<typename T,typename... Args>
    void write(T first,Args... args){ write(first),Spc,write(args...); }
}using namespace _TvT_;
typedef double ldb;
const ldb eps=1e-9;
const int maxn=2e5+10;
const int B=450;

int n,m;
int res[maxn];
ldb f[3][B];
void init()
{
    const int N=200000,M=448;
    For(i,0,N)
    {
        int lt=(i+1)%3,nw=i%3;
        f[nw][0]=1.0;
        ldb mn=1.0;
        For(j,1,min(M,i-1)) f[nw][j]=(i-j)*1.0/i*f[lt][j]+j*1.0/i*f[lt][j-1];
        For(j,1,min(M,i-1)) if(fabs(f[nw][j]-0.5)<mn) mn=fabs(f[nw][j]-0.5),res[i]=j;
    }
}

signed main()
{
    init();
    int T;rd(T);while(T--){
        int n;rd(n);
        printf("%d\n",res[n]);
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 261ms
memory: 4480kb

input:

5
2
3
6
7
8

output:

1
1
2
1
2

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 269ms
memory: 4608kb

input:

100000
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...

output:

1
1
1
1
2
1
2
1
2
1
2
2
2
2
3
2
3
2
3
2
3
2
3
2
3
2
3
2
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
5
3
5
3
5
3
5
3
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
6
4
6
4
6
4
6
4
6
4
6
4
6
4
6
4
6
4
6
4
6
5
6
5
6
5
6
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
7
5
8
5
8
5
8
5
8
6
8
6
8
6
8
6
8
6
8
6
8
6
8
6
...

result:

ok 100000 lines

Test #3:

score: 0
Accepted
time: 267ms
memory: 4480kb

input:

100000
100001
100002
100003
100004
100005
100006
100007
100008
100009
100010
100011
100012
100013
100014
100015
100016
100017
100018
100019
100020
100021
100022
100023
100024
100025
100026
100027
100028
100029
100030
100031
100032
100033
100034
100035
100036
100037
100038
100039
100040
100041
100042...

output:

156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
213
156
...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed