Submission #1044981

# Submission time Handle Problem Language Result Execution time Memory
1044981 2024-08-05T15:19:45 Z urd05 Bring Down the Grading Server (CEOI23_gradingserver) C++17
65 / 100
2578 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

long long s;
int q;
typedef pair<long long,long long> P;
typedef pair<long long,P> iP;
map<iP,long long> mp[2];

bool solve(long long a1,long long f1,long long a2,long long f2,int t=0) {
if (a2<=-f1*s) return true;
if (a1<=-f2*s) return false;
    if (a1>=s&&a2<s) {
        return true;
    }
    if (0<a1&&a1<s&&a2<=0) {
if (f2==0) {
return !solve(a2-a1,f2,a1,f1,1-t);
}
        return true;
    }
    if (a1<=0&&a2>=s) {
        return false;
    }
    if (a2>=s) {
        return !solve(a2-a1,f2,a1,f1,1-t);
    }
    if (a1<=0) {
        if (a2<=0) {
            long long tt=min((-a1)/s+1,(-a2)/s+1);
tt=min(tt,f1);
tt=min(tt,f2);
            return solve(a1+tt*s,f1-tt,a2+tt*s,f2-tt,t);
        }
if (f2==0) return false;
        return !solve(a2,f2-1,a1+s,f1,1-t);
    }
assert(0<a1&&a1<s&&a2>0&&a2<s);
        if (f2==0) {
        return !solve(a2-a1,f2,a1,f1,1-t);
    }
    long long b2=s-a2;
    long long b1=s-a1;
    if (b2*f2>=b1) {
        return true;
    }
    if ((s-a1)*(f1+1)>=2*s-a2) {
        long long diff=(s-a1)*(f1+1)-2*s+a2;
        diff=diff/(b2*(f1+1))+1;
        diff=min(diff,f2);
            return solve(a1+b2*diff,f1,a2,f2-diff,t);
    }
    bool flag=false;
    if (f2>10*s||f1>10*s) {
        return true;
    }
    if (b2*max(f1,1LL)>=(10*s+1)/(f2*f2)) {
        return true;
    }
    if (mp[t].find(iP(f1,P(b2,f2)))!=mp[t].end()) {
        long long got=mp[t][iP(f1,P(b2,f2))];
        return a1+s*f2>=got;
    }
    long long lo=0;
    long long hi=1e12+7;
    if (solve(a2,f2-1,hi-s*f2+s,f1,1-t)&&solve(a2-hi+s*f2,f2,hi-s*f2,f1,1-t)) {
        mp[t][iP(f1,P(b2,f2))]=1e17+1;
        return false;
    }
    while (lo+1<hi) {
        long long mid=(lo+hi)/2;
        if (solve(a2,f2-1,mid-s*f2+s,f1,1-t)&&solve(a2-mid+s*f2,f2,mid-s*f2,f1,1-t)) {
            lo=mid;
        }
        else {
            hi=mid;
        }
    }
    mp[t][iP(f1,P(b2,f2))]=hi;
    return (a1+s*f2>=hi);
}

int main(void) {
    scanf("%lld %d",&s,&q);
    for(int i=0;i<q;i++) {
        long long c1,f1,c2,f2;
        scanf("%lld %lld %lld %lld",&c1,&f1,&c2,&f2);
        int got=solve(c1-s*f2,f1,c2-s*f1,f2);
        printf("%s\n",got?"YES":"NO");
    }
}

Compilation message

gradingserver.cpp: In function 'bool solve(long long int, long long int, long long int, long long int, int)':
gradingserver.cpp:53:10: warning: unused variable 'flag' [-Wunused-variable]
   53 |     bool flag=false;
      |          ^~~~
gradingserver.cpp: In function 'int main()':
gradingserver.cpp:84:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |     scanf("%lld %d",&s,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
gradingserver.cpp:87:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         scanf("%lld %lld %lld %lld",&c1,&f1,&c2,&f2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 543 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 4104 KB Output is correct
12 Correct 55 ms 3924 KB Output is correct
13 Correct 90 ms 3920 KB Output is correct
14 Correct 61 ms 3968 KB Output is correct
15 Correct 111 ms 3924 KB Output is correct
16 Correct 69 ms 3944 KB Output is correct
17 Correct 69 ms 4008 KB Output is correct
18 Correct 48 ms 3924 KB Output is correct
19 Correct 103 ms 4700 KB Output is correct
20 Correct 100 ms 4516 KB Output is correct
21 Correct 110 ms 4948 KB Output is correct
22 Correct 94 ms 4972 KB Output is correct
23 Correct 79 ms 4756 KB Output is correct
24 Correct 85 ms 4556 KB Output is correct
25 Correct 98 ms 4728 KB Output is correct
26 Correct 57 ms 4612 KB Output is correct
27 Correct 53 ms 4696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 13652 KB Output is correct
2 Correct 78 ms 12472 KB Output is correct
3 Correct 82 ms 13292 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 4104 KB Output is correct
12 Correct 55 ms 3924 KB Output is correct
13 Correct 90 ms 3920 KB Output is correct
14 Correct 61 ms 3968 KB Output is correct
15 Correct 111 ms 3924 KB Output is correct
16 Correct 69 ms 3944 KB Output is correct
17 Correct 69 ms 4008 KB Output is correct
18 Correct 48 ms 3924 KB Output is correct
19 Correct 103 ms 4700 KB Output is correct
20 Correct 100 ms 4516 KB Output is correct
21 Correct 110 ms 4948 KB Output is correct
22 Correct 94 ms 4972 KB Output is correct
23 Correct 79 ms 4756 KB Output is correct
24 Correct 85 ms 4556 KB Output is correct
25 Correct 98 ms 4728 KB Output is correct
26 Correct 57 ms 4612 KB Output is correct
27 Correct 53 ms 4696 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 51 ms 3920 KB Output is correct
30 Correct 57 ms 4076 KB Output is correct
31 Correct 61 ms 3920 KB Output is correct
32 Correct 60 ms 3920 KB Output is correct
33 Correct 82 ms 3924 KB Output is correct
34 Correct 106 ms 3924 KB Output is correct
35 Correct 62 ms 3668 KB Output is correct
36 Correct 48 ms 3924 KB Output is correct
37 Correct 72 ms 4436 KB Output is correct
38 Correct 66 ms 4432 KB Output is correct
39 Correct 109 ms 4804 KB Output is correct
40 Correct 80 ms 4804 KB Output is correct
41 Correct 76 ms 4688 KB Output is correct
42 Correct 82 ms 4432 KB Output is correct
43 Correct 133 ms 4432 KB Output is correct
44 Correct 81 ms 4688 KB Output is correct
45 Correct 93 ms 4568 KB Output is correct
46 Correct 237 ms 6156 KB Output is correct
47 Correct 140 ms 6224 KB Output is correct
48 Correct 170 ms 6196 KB Output is correct
49 Correct 175 ms 6224 KB Output is correct
50 Correct 330 ms 6364 KB Output is correct
51 Correct 279 ms 5820 KB Output is correct
52 Correct 76 ms 4552 KB Output is correct
53 Correct 52 ms 4556 KB Output is correct
54 Correct 57 ms 4528 KB Output is correct
55 Correct 67 ms 5816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 4104 KB Output is correct
12 Correct 55 ms 3924 KB Output is correct
13 Correct 90 ms 3920 KB Output is correct
14 Correct 61 ms 3968 KB Output is correct
15 Correct 111 ms 3924 KB Output is correct
16 Correct 69 ms 3944 KB Output is correct
17 Correct 69 ms 4008 KB Output is correct
18 Correct 48 ms 3924 KB Output is correct
19 Correct 103 ms 4700 KB Output is correct
20 Correct 100 ms 4516 KB Output is correct
21 Correct 110 ms 4948 KB Output is correct
22 Correct 94 ms 4972 KB Output is correct
23 Correct 79 ms 4756 KB Output is correct
24 Correct 85 ms 4556 KB Output is correct
25 Correct 98 ms 4728 KB Output is correct
26 Correct 57 ms 4612 KB Output is correct
27 Correct 53 ms 4696 KB Output is correct
28 Correct 81 ms 13652 KB Output is correct
29 Correct 78 ms 12472 KB Output is correct
30 Correct 82 ms 13292 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 91 ms 13392 KB Output is correct
33 Correct 81 ms 12208 KB Output is correct
34 Correct 87 ms 12876 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 344 KB Output is correct
37 Correct 51 ms 3916 KB Output is correct
38 Correct 54 ms 3920 KB Output is correct
39 Correct 63 ms 4124 KB Output is correct
40 Correct 61 ms 3924 KB Output is correct
41 Correct 105 ms 4084 KB Output is correct
42 Correct 73 ms 3956 KB Output is correct
43 Correct 63 ms 3240 KB Output is correct
44 Correct 53 ms 2388 KB Output is correct
45 Correct 63 ms 3596 KB Output is correct
46 Correct 70 ms 3180 KB Output is correct
47 Correct 112 ms 3816 KB Output is correct
48 Correct 90 ms 3372 KB Output is correct
49 Correct 83 ms 2768 KB Output is correct
50 Correct 82 ms 2064 KB Output is correct
51 Correct 98 ms 1620 KB Output is correct
52 Correct 72 ms 1912 KB Output is correct
53 Correct 53 ms 2736 KB Output is correct
54 Runtime error 562 ms 1048576 KB Execution killed with signal 9
55 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 59 ms 3896 KB Output is correct
12 Correct 63 ms 2388 KB Output is correct
13 Correct 61 ms 3896 KB Output is correct
14 Correct 64 ms 4104 KB Output is correct
15 Correct 77 ms 3924 KB Output is correct
16 Correct 68 ms 3936 KB Output is correct
17 Correct 69 ms 2444 KB Output is correct
18 Correct 53 ms 3944 KB Output is correct
19 Correct 88 ms 5968 KB Output is correct
20 Correct 434 ms 17304 KB Output is correct
21 Correct 2021 ms 51724 KB Output is correct
22 Correct 2578 ms 60576 KB Output is correct
23 Correct 970 ms 33024 KB Output is correct
24 Correct 1247 ms 37888 KB Output is correct
25 Correct 270 ms 13852 KB Output is correct
26 Correct 96 ms 9040 KB Output is correct
27 Correct 1862 ms 46340 KB Output is correct
28 Correct 962 ms 30392 KB Output is correct
29 Correct 923 ms 28616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 60 ms 4084 KB Output is correct
3 Correct 55 ms 3924 KB Output is correct
4 Correct 60 ms 3968 KB Output is correct
5 Correct 59 ms 3924 KB Output is correct
6 Correct 80 ms 3960 KB Output is correct
7 Correct 85 ms 3960 KB Output is correct
8 Correct 99 ms 3920 KB Output is correct
9 Correct 66 ms 3952 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 50 ms 4104 KB Output is correct
12 Correct 55 ms 3924 KB Output is correct
13 Correct 90 ms 3920 KB Output is correct
14 Correct 61 ms 3968 KB Output is correct
15 Correct 111 ms 3924 KB Output is correct
16 Correct 69 ms 3944 KB Output is correct
17 Correct 69 ms 4008 KB Output is correct
18 Correct 48 ms 3924 KB Output is correct
19 Correct 103 ms 4700 KB Output is correct
20 Correct 100 ms 4516 KB Output is correct
21 Correct 110 ms 4948 KB Output is correct
22 Correct 94 ms 4972 KB Output is correct
23 Correct 79 ms 4756 KB Output is correct
24 Correct 85 ms 4556 KB Output is correct
25 Correct 98 ms 4728 KB Output is correct
26 Correct 57 ms 4612 KB Output is correct
27 Correct 53 ms 4696 KB Output is correct
28 Correct 81 ms 13652 KB Output is correct
29 Correct 78 ms 12472 KB Output is correct
30 Correct 82 ms 13292 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 51 ms 3920 KB Output is correct
34 Correct 57 ms 4076 KB Output is correct
35 Correct 61 ms 3920 KB Output is correct
36 Correct 60 ms 3920 KB Output is correct
37 Correct 82 ms 3924 KB Output is correct
38 Correct 106 ms 3924 KB Output is correct
39 Correct 62 ms 3668 KB Output is correct
40 Correct 48 ms 3924 KB Output is correct
41 Correct 72 ms 4436 KB Output is correct
42 Correct 66 ms 4432 KB Output is correct
43 Correct 109 ms 4804 KB Output is correct
44 Correct 80 ms 4804 KB Output is correct
45 Correct 76 ms 4688 KB Output is correct
46 Correct 82 ms 4432 KB Output is correct
47 Correct 133 ms 4432 KB Output is correct
48 Correct 81 ms 4688 KB Output is correct
49 Correct 93 ms 4568 KB Output is correct
50 Correct 237 ms 6156 KB Output is correct
51 Correct 140 ms 6224 KB Output is correct
52 Correct 170 ms 6196 KB Output is correct
53 Correct 175 ms 6224 KB Output is correct
54 Correct 330 ms 6364 KB Output is correct
55 Correct 279 ms 5820 KB Output is correct
56 Correct 76 ms 4552 KB Output is correct
57 Correct 52 ms 4556 KB Output is correct
58 Correct 57 ms 4528 KB Output is correct
59 Correct 67 ms 5816 KB Output is correct
60 Correct 91 ms 13392 KB Output is correct
61 Correct 81 ms 12208 KB Output is correct
62 Correct 87 ms 12876 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 51 ms 3916 KB Output is correct
66 Correct 54 ms 3920 KB Output is correct
67 Correct 63 ms 4124 KB Output is correct
68 Correct 61 ms 3924 KB Output is correct
69 Correct 105 ms 4084 KB Output is correct
70 Correct 73 ms 3956 KB Output is correct
71 Correct 63 ms 3240 KB Output is correct
72 Correct 53 ms 2388 KB Output is correct
73 Correct 63 ms 3596 KB Output is correct
74 Correct 70 ms 3180 KB Output is correct
75 Correct 112 ms 3816 KB Output is correct
76 Correct 90 ms 3372 KB Output is correct
77 Correct 83 ms 2768 KB Output is correct
78 Correct 82 ms 2064 KB Output is correct
79 Correct 98 ms 1620 KB Output is correct
80 Correct 72 ms 1912 KB Output is correct
81 Correct 53 ms 2736 KB Output is correct
82 Runtime error 562 ms 1048576 KB Execution killed with signal 9
83 Halted 0 ms 0 KB -