Submission #638566

# Submission time Handle Problem Language Result Execution time Memory
638566 2022-09-06T11:54:34 Z morasha3 Alternating Heights (CCO22_day1problem1) C++17
6 / 25
1000 ms 7132 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef   double ld;
const ll mod=1e9+7;
#define endl '\n'
ll n,k,q,arr[3007],vis[3007],s[3007];
vector<vector<ll>>v(3007);
bool f=0;
void dfs(ll idx)
{
    vis[idx]=1;
    s[idx]=1;
    for(int i=0; i<v[idx].size(); i++)
    {
        if(vis[v[idx][i]]&&s[v[idx][i]])
        {
            f=1;
            break;
        }
        else if(vis[v[idx][i]])
            continue;
        dfs(v[idx][i]);
    }
    s[idx]=0;
}


int32_t main()
{
    //freopen("jumping.in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k>>q;
    for(int i=0; i<n; i++)
        cin>>arr[i];
    ll m[n];
    for(int i=0;i<n;i++)m[i]=i;
    for(int h=0;h<2;h++)
    {
        for(int i=h;i<n;i+=2)
        {
            ll r=i+1,c=0;
            while(r<n)
            {
                if(c==0)
                {
                    c++;
                    v[arr[r]-1].push_back(arr[r-1]-1);
                }
                else
                {
                    c=0;
                    v[arr[r-1]-1].push_back(arr[r]-1);
                }
                for(int j=0;j<k;j++)vis[j]=0;
                f=0;
                for(int j=0;j<k;j++)
                {
                    if(vis[j]==0)
                        dfs(j);
                }
                if(f)break;
                r++;
            }
            m[i]=r-1;
            for(int j=0;j<k;j++)v[j].clear();
        }
    }
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        a--,b--;
        if(m[a]>=b)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }

    return 0;

}

Compilation message

Main.cpp: In function 'void dfs(ll)':
Main.cpp:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int i=0; i<v[idx].size(); i++)
      |                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 186 ms 6192 KB Output is correct
2 Correct 184 ms 6284 KB Output is correct
3 Correct 195 ms 6152 KB Output is correct
4 Correct 148 ms 6216 KB Output is correct
5 Correct 148 ms 6268 KB Output is correct
6 Correct 176 ms 6188 KB Output is correct
7 Correct 188 ms 6236 KB Output is correct
8 Correct 195 ms 6276 KB Output is correct
9 Correct 245 ms 6428 KB Output is correct
10 Execution timed out 1090 ms 468 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 163 ms 6280 KB Output is correct
2 Correct 160 ms 6292 KB Output is correct
3 Correct 166 ms 6204 KB Output is correct
4 Correct 133 ms 7132 KB Output is correct
5 Correct 163 ms 6400 KB Output is correct
6 Correct 173 ms 6192 KB Output is correct
7 Correct 181 ms 6244 KB Output is correct
8 Correct 172 ms 6248 KB Output is correct
9 Correct 173 ms 6520 KB Output is correct
10 Correct 220 ms 7080 KB Output is correct
11 Correct 194 ms 7052 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Execution timed out 1075 ms 476 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 186 ms 6192 KB Output is correct
2 Correct 184 ms 6284 KB Output is correct
3 Correct 195 ms 6152 KB Output is correct
4 Correct 148 ms 6216 KB Output is correct
5 Correct 148 ms 6268 KB Output is correct
6 Correct 176 ms 6188 KB Output is correct
7 Correct 188 ms 6236 KB Output is correct
8 Correct 195 ms 6276 KB Output is correct
9 Correct 245 ms 6428 KB Output is correct
10 Execution timed out 1090 ms 468 KB Time limit exceeded
11 Halted 0 ms 0 KB -