Submission #1100870

# Submission time Handle Problem Language Result Execution time Memory
1100870 2024-10-14T20:49:51 Z Raj Circle Passing (EGOI24_circlepassing) C++11
0 / 100
2000 ms 568 KB
#include <bits/stdc++.h>
using namespace std;
int n,M,Q;
unordered_map <int,int> v;
int stanga(int x,int y)
{

    int cnt=0;
    while(x!=y)
    {
        cnt++;
        x--;
        if(x<0)
            x=2*n-1;
    }
    return cnt;
}
int dreapta(int x,int y)
{
    int cnt=0;
    while(x!=y)
    {
        cnt++;
        x++;
        if(x>=2*n)
            x=0;
    }
    return cnt;
}
int shc(int x, int y)
{
    int cp=x;
    int pas1=0;
    int pas4=0;
    int pas3=0;
    int pas2=0;
    while(x!=y)
    {
        if(v[x]!=0)
        {
            pas1+=stanga(v[x],y)+1;
            pas2+=dreapta(v[x],y)+1;
            break;
        }
        ++pas1;
        ++pas2;
        x--;
        if(x<0)
            x=2*n-1;
    }
    pas1=min(pas1,pas2);
    x=cp;
    while(x!=y)
    {
        if(v[x]!=0)
        {
            pas3+=stanga(v[x],y)+1;
            pas4+=dreapta(v[x],y)+1;
            break;
        }
        pas3++;
        ++pas4;
        x++;
        if(x>=2*n)
            x=0;
    }
    pas2=min(pas3,pas4);
    return min(pas1,pas2);
}
int main()
{
    cin>>n>>M>>Q;
    for(int i=1;i<=M;++i)
    {
        int x;
        cin>>x;
        if(x>=n)
        {
            v[x-n]=x;
            v[x]=x-n;
        }
        if(x<n)
        {
            v[x+n]=x;
            v[x]=x+n;
        }
    }
    for(int i=1;i<=Q;++i)
    {
        int a,b;
        cin>>a>>b;
        cout<<min(shc(a,b),min(stanga(a,b),dreapta(a,b)))<<'\n';
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 336 KB Output is correct
2 Correct 35 ms 336 KB Output is correct
3 Correct 48 ms 568 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Execution timed out 2050 ms 436 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Incorrect 2 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 5 ms 336 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Incorrect 2 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2059 ms 336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 336 KB Output is correct
2 Correct 35 ms 336 KB Output is correct
3 Correct 48 ms 568 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Execution timed out 2050 ms 436 KB Time limit exceeded
6 Halted 0 ms 0 KB -