Submission #990558

# Submission time Handle Problem Language Result Execution time Memory
990558 2024-05-30T16:08:53 Z alexdd Mađioničar (COI22_madionicar) C++17
100 / 100
1297 ms 1700 KB
#include<bits/stdc++.h>
using namespace std;
int n,cntq;

string s;
bool verif(int le, int ri)
{
    for(int i=0;i<=ri-le;i++)
        if(s[le+i]!=s[ri-i])
            return 0;
    return 1;
}

int p[100005];
bool query(int le, int ri)
{
    if(le<1 || ri>n || le>ri)
        return 0;
    if(le==ri)
        return 1;
    cntq++;
    //return verif(le,ri);
    if(cntq>200000)
    {
        while(1);
    }
    int aux;
    cout<<"? "<<le<<" "<<ri<<endl;
    cin>>aux;
    return aux;
}
signed main()
{
    cin>>n;

    /*s.resize(n+2);
    for(int i=1;i<=n;i++)
    {
        int c = rand()%26;
        s[i] = c+'a';
    }*/

    int le=1,ri=1,mxm=1;
    for(int i=1;i<=n;i++)
    {
        p[i] = max(max(0,(mxm+1)/2), min(ri-i, p[le + (ri-i)]));
        while(query(i-p[i],i+p[i]))
            p[i]++;
        if(i+p[i] > ri)
        {
            le = i-p[i];
            ri = i+p[i];
        }
        mxm = max(mxm, 2*p[i]-1);
    }
    le=1;
    ri=1;
    for(int i=1;i<n;i++)
    {
        p[i] = max(max(0,mxm/2), min(ri-i-1, p[le+(ri-i)-1]));
        while(query(i-p[i],i+1+p[i]))
            p[i]++;
        if(i+1+p[i] > ri)
        {
            le = i-p[i];
            ri = i+1+p[i];
        }
        mxm = max(mxm, 2*p[i]);
    }
    cout<<"! "<<mxm<<endl;
   // cout<<cntq<<" queries\n";
    return 0;
}
/**
neven

1 2 3 4 5 6 7 8 9
    l       r
    a b c b a

1 2 3 4 5 6 7 8 9
    l         r
    a b c c b a
*/
# Verdict Execution time Memory Grader output
1 Correct 82 ms 600 KB Output is correct
2 Correct 75 ms 344 KB Output is correct
3 Correct 64 ms 932 KB Output is correct
4 Correct 68 ms 592 KB Output is correct
5 Correct 89 ms 344 KB Output is correct
6 Correct 76 ms 344 KB Output is correct
7 Correct 40 ms 428 KB Output is correct
8 Correct 38 ms 340 KB Output is correct
9 Correct 61 ms 440 KB Output is correct
10 Correct 76 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 600 KB Output is correct
2 Correct 75 ms 344 KB Output is correct
3 Correct 64 ms 932 KB Output is correct
4 Correct 68 ms 592 KB Output is correct
5 Correct 89 ms 344 KB Output is correct
6 Correct 76 ms 344 KB Output is correct
7 Correct 40 ms 428 KB Output is correct
8 Correct 38 ms 340 KB Output is correct
9 Correct 61 ms 440 KB Output is correct
10 Correct 76 ms 596 KB Output is correct
11 Correct 746 ms 1052 KB Output is correct
12 Correct 748 ms 976 KB Output is correct
13 Correct 800 ms 1556 KB Output is correct
14 Correct 747 ms 932 KB Output is correct
15 Correct 752 ms 1172 KB Output is correct
16 Correct 365 ms 1496 KB Output is correct
17 Correct 416 ms 948 KB Output is correct
18 Correct 799 ms 944 KB Output is correct
19 Correct 379 ms 964 KB Output is correct
20 Correct 765 ms 1360 KB Output is correct
21 Correct 830 ms 1288 KB Output is correct
22 Correct 833 ms 1556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1188 ms 1484 KB Output is correct
2 Correct 267 ms 1352 KB Output is correct
3 Correct 1192 ms 1648 KB Output is correct
4 Correct 793 ms 1076 KB Output is correct
5 Correct 633 ms 1276 KB Output is correct
6 Correct 1187 ms 1100 KB Output is correct
7 Correct 570 ms 1288 KB Output is correct
8 Correct 1210 ms 1368 KB Output is correct
9 Correct 1202 ms 1028 KB Output is correct
10 Correct 1201 ms 1700 KB Output is correct
11 Correct 578 ms 1320 KB Output is correct
12 Correct 663 ms 852 KB Output is correct
13 Correct 1165 ms 1524 KB Output is correct
14 Correct 1043 ms 960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 600 KB Output is correct
2 Correct 75 ms 344 KB Output is correct
3 Correct 64 ms 932 KB Output is correct
4 Correct 68 ms 592 KB Output is correct
5 Correct 89 ms 344 KB Output is correct
6 Correct 76 ms 344 KB Output is correct
7 Correct 40 ms 428 KB Output is correct
8 Correct 38 ms 340 KB Output is correct
9 Correct 61 ms 440 KB Output is correct
10 Correct 76 ms 596 KB Output is correct
11 Correct 746 ms 1052 KB Output is correct
12 Correct 748 ms 976 KB Output is correct
13 Correct 800 ms 1556 KB Output is correct
14 Correct 747 ms 932 KB Output is correct
15 Correct 752 ms 1172 KB Output is correct
16 Correct 365 ms 1496 KB Output is correct
17 Correct 416 ms 948 KB Output is correct
18 Correct 799 ms 944 KB Output is correct
19 Correct 379 ms 964 KB Output is correct
20 Correct 765 ms 1360 KB Output is correct
21 Correct 830 ms 1288 KB Output is correct
22 Correct 833 ms 1556 KB Output is correct
23 Correct 1188 ms 1484 KB Output is correct
24 Correct 267 ms 1352 KB Output is correct
25 Correct 1192 ms 1648 KB Output is correct
26 Correct 793 ms 1076 KB Output is correct
27 Correct 633 ms 1276 KB Output is correct
28 Correct 1187 ms 1100 KB Output is correct
29 Correct 570 ms 1288 KB Output is correct
30 Correct 1210 ms 1368 KB Output is correct
31 Correct 1202 ms 1028 KB Output is correct
32 Correct 1201 ms 1700 KB Output is correct
33 Correct 578 ms 1320 KB Output is correct
34 Correct 663 ms 852 KB Output is correct
35 Correct 1165 ms 1524 KB Output is correct
36 Correct 1043 ms 960 KB Output is correct
37 Correct 1177 ms 1476 KB Output is correct
38 Correct 1204 ms 1212 KB Output is correct
39 Correct 1266 ms 1052 KB Output is correct
40 Correct 1196 ms 1060 KB Output is correct
41 Correct 1108 ms 1288 KB Output is correct
42 Correct 839 ms 1144 KB Output is correct
43 Correct 564 ms 704 KB Output is correct
44 Correct 1215 ms 1444 KB Output is correct
45 Correct 640 ms 1296 KB Output is correct
46 Correct 1276 ms 1412 KB Output is correct
47 Correct 1297 ms 1476 KB Output is correct
48 Correct 1140 ms 1296 KB Output is correct
49 Correct 635 ms 1080 KB Output is correct
50 Correct 622 ms 1332 KB Output is correct
51 Correct 1253 ms 1328 KB Output is correct
52 Correct 1272 ms 1292 KB Output is correct