Submission #850262

# Submission time Handle Problem Language Result Execution time Memory
850262 2023-09-16T08:51:04 Z alexdd Amusement Park (JOI17_amusement_park) C++17
10 / 100
20 ms 5008 KB
#include "Joi.h"
#include<bits/stdc++.h>
using namespace std;
static bool visited[10005];
static bool visited2[10005];
static vector<int> ord;
static vector<int> con[10005];
static bool done[10005];
static int maxd[10005];
static int siz[10005];
static bool cmp(int x, int y)
{
    if(maxd[x]<maxd[y])
        return x;
    if(maxd[x]>maxd[y])
        return y;
    return x<y;
}
static void dfs_init(int nod)
{
    visited2[nod]=1;
    siz[nod]=1;
    maxd[nod]=1;
    for(auto adj:con[nod])
    {
        if(!visited2[adj])
        {
            dfs_init(adj);
            maxd[nod]=max(maxd[nod],maxd[adj]+1);
            siz[nod]+=siz[adj];
        }
    }
}
static void dfs(int nod)
{
    visited[nod]=1;
    sort(con[nod].begin(),con[nod].end(),cmp);
    ord.push_back(nod);
    for(auto adj:con[nod])
    {
        if(!visited[adj])
        {
            dfs(adj);
            ord.push_back(nod);
        }
    }
}
void Joi(int N, int M, int A[], int B[], long long X, int T)
{
    ord.clear();
    for(int i=0;i<N;i++)
    {
        visited[i]=0;
        visited2[i]=0;
        con[i].clear();
        done[i]=0;
    }

    for(int i=0;i<M;i++)
    {
        con[A[i]].push_back(B[i]);
        con[B[i]].push_back(A[i]);
    }
    dfs_init(0);
    dfs(0);
    int cnt=0;
    for(int i=0;i<(int)ord.size();i++)
    {
        if(!done[ord[i]])
        {
            if(((1LL<<cnt)&X))
                MessageBoard(ord[i],1);
            else
                MessageBoard(ord[i],0);
            cnt=(cnt+1)%60;
            done[ord[i]]=1;
        }
    }
}


#include "Ioi.h"
#include<bits/stdc++.h>
using namespace std;
static bool visited[10005];
static bool visited2[10005];
static vector<int> ord;
static vector<int> con[10005];
static bool done[10005];
static int p[50005];
static int poz[10005];
static int fr[65];
static int frst[65];
static int frdr[65];
static int care[10005];
static int maxd[10005];
static int siz[10005];
static bool cmp(int x, int y)
{
    if(maxd[x]<maxd[y])
        return x;
    if(maxd[x]>maxd[y])
        return y;
    return x<y;
}
static void dfs_init(int nod)
{
    visited2[nod]=1;
    siz[nod]=1;
    maxd[nod]=1;
    for(auto adj:con[nod])
    {
        if(!visited2[adj])
        {
            dfs_init(adj);
            maxd[nod]=max(maxd[nod],maxd[adj]+1);
            siz[nod]+=siz[adj];
        }
    }
}
static void dfs(int nod)
{
    visited[nod]=1;
    sort(con[nod].begin(),con[nod].end(),cmp);
    poz[nod]=ord.size();
    ord.push_back(nod);
    for(auto adj:con[nod])
    {
        if(!visited[adj])
        {
            dfs(adj);
            ord.push_back(nod);
        }
    }
}
long long Ioi(int N, int M, int A[], int B[], int P, int V, int T)
{
    ord.clear();
    for(int i=0;i<N;i++)
    {
        visited[i]=0;
        visited2[i]=0;
        con[i].clear();
        done[i]=0;
    }
    for(int i=0;i<60;i++)
    {
        fr[i]=0;
        frst[i]=0;
        frdr[i]=0;
    }

    for(int i=0;i<M;i++)
    {
        con[A[i]].push_back(B[i]);
        con[B[i]].push_back(A[i]);
    }
    dfs_init(0);
    dfs(0);
    int cnt=0;
    for(int i=0;i<(int)ord.size();i++)
    {
        if(!done[ord[i]])
        {
            care[ord[i]]=cnt;
            cnt=(cnt+1)%60;
            done[ord[i]]=1;
        }
        p[i]=care[ord[i]];
        //cout<<i<<" "<<ord[i]<<"  "<<p[i]<<" zzz\n";
    }
    int cntst=0,cntdr=0,pozst,pozdr;
    for(int i=poz[P];i<(int)ord.size();i++)
    {
        if(frdr[p[i]]==0)
        {
            frdr[p[i]]=1;
            cntdr++;
            if(cntdr==60)
            {
                pozdr=i-poz[P];
                break;
            }
        }
    }
    for(int i=poz[P];i>=0;i--)
    {
        if(frst[p[i]]==0)
        {
            frst[p[i]]=1;
            cntst++;
            if(cntst==60)
            {
                pozst=poz[P]-i;
                break;
            }
        }
    }
    long long rez=0;
    int cate=0;
    if((cntdr==60 && cntst<60) || (cntdr==60 && cntst==60 && pozdr<pozst) || (cntdr<60 && cntst<60 && poz[P]>ord.size()-poz[P]))
    {
        for(int i=poz[P];i<(int)ord.size();i++)
        {
            if(fr[p[i]]==0)
            {
                if(V==1) rez += (1LL<<(p[i]));
                fr[p[i]]=1;
                cate++;
                if(cate==60)
                    return rez;
            }
            if(i+1<(int)ord.size()) V = Move(ord[i+1]);
        }
        for(int i=(int)ord.size()-1;i>=0;i--)
        {
            if(fr[p[i]]==0)
            {
                if(V==1) rez += (1LL<<(p[i]));
                fr[p[i]]=1;
                cate++;
                if(cate==60)
                    return rez;
            }
            V = Move(ord[i-1]);
        }
    }
    else
    {
        for(int i=poz[P];i>=0;i--)
        {
            if(fr[p[i]]==0)
            {
                if(V==1) rez += (1LL<<(p[i]));
                fr[p[i]]=1;
                cate++;
                if(cate==60)
                    return rez;
            }
            if(i-1>=0) V = Move(ord[i-1]);
        }
        for(int i=0;i<(int)ord.size();i++)
        {
            if(fr[p[i]]==0)
            {
                if(V==1) rez += (1LL<<(p[i]));
                fr[p[i]]=1;
                cate++;
                if(cate==60)
                    return rez;
            }
            V = Move(ord[i+1]);
        }
    }
    return rez;
}

Compilation message

Ioi.cpp: In function 'long long int Ioi(int, int, int*, int*, int, int, int)':
Ioi.cpp:120:109: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |     if((cntdr==60 && cntst<60) || (cntdr==60 && cntst==60 && pozdr<pozst) || (cntdr<60 && cntst<60 && poz[P]>ord.size()-poz[P]))
      |                                                                                                       ~~~~~~^~~~~~~~~~~~~~~~~~
Ioi.cpp:120:59: warning: 'pozst' may be used uninitialized in this function [-Wmaybe-uninitialized]
  120 |     if((cntdr==60 && cntst<60) || (cntdr==60 && cntst==60 && pozdr<pozst) || (cntdr<60 && cntst<60 && poz[P]>ord.size()-poz[P]))
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
Ioi.cpp:120:59: warning: 'pozdr' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1308 KB Output is correct
2 Correct 1 ms 1308 KB Output is correct
3 Correct 1 ms 1304 KB Output is correct
4 Correct 1 ms 1296 KB Output is correct
5 Correct 1 ms 1304 KB Output is correct
6 Correct 1 ms 1308 KB Output is correct
7 Correct 1 ms 1296 KB Output is correct
8 Runtime error 1 ms 1116 KB Execution killed with signal 6
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 4960 KB Output is correct
2 Runtime error 8 ms 3420 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1308 KB Output is correct
2 Correct 1 ms 1296 KB Output is correct
3 Correct 0 ms 1304 KB Output is correct
4 Correct 2 ms 1840 KB Output is correct
5 Correct 3 ms 1836 KB Output is correct
6 Correct 3 ms 1852 KB Output is correct
7 Correct 2 ms 1844 KB Output is correct
8 Correct 2 ms 1836 KB Output is correct
9 Correct 9 ms 4764 KB Output is correct
10 Correct 9 ms 4584 KB Output is correct
11 Correct 10 ms 4580 KB Output is correct
12 Correct 1 ms 1308 KB Output is correct
13 Correct 1 ms 1308 KB Output is correct
14 Correct 1 ms 1296 KB Output is correct
15 Correct 0 ms 1308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 3420 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 5008 KB Output is correct
2 Runtime error 8 ms 3420 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -