답안 #638507

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638507 2022-09-06T10:10:13 Z morasha3 Alternating Heights (CCO22_day1problem1) C++17
6 / 25
1000 ms 13064 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]=0;
        ll c=0;
        for(int j=i+1; j<n; j++)
        {
            if(c==0)
            {
                c++;
                v[arr[j]-1].push_back(arr[j-1]-1);
            }
            else
            {
                c=0;
                v[arr[j-1]-1].push_back(arr[j]-1);
            }
            f=0;
            for(int i=0; i<k; i++)
                vis[i]=0;

            for(int i=0; i<k; i++)
            {
                if(vis[i]==0)
                    dfs(i);
            }
            if(f)
            {
                m[i]=j-1;
                break;
            }
        }
        if(f==0)
            m[i]=n-1;
        for(int i=0;i<k;i++)v[i].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++)
      |                  ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 12752 KB Output is correct
2 Correct 182 ms 12668 KB Output is correct
3 Correct 206 ms 12732 KB Output is correct
4 Correct 134 ms 7320 KB Output is correct
5 Correct 176 ms 9292 KB Output is correct
6 Correct 171 ms 12688 KB Output is correct
7 Correct 192 ms 12780 KB Output is correct
8 Correct 176 ms 12772 KB Output is correct
9 Correct 263 ms 13064 KB Output is correct
10 Execution timed out 1084 ms 468 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 179 ms 11124 KB Output is correct
2 Correct 160 ms 11132 KB Output is correct
3 Correct 169 ms 10968 KB Output is correct
4 Correct 134 ms 8220 KB Output is correct
5 Correct 166 ms 9396 KB Output is correct
6 Correct 166 ms 11068 KB Output is correct
7 Correct 162 ms 11044 KB Output is correct
8 Correct 168 ms 11004 KB Output is correct
9 Correct 178 ms 11368 KB Output is correct
10 Correct 224 ms 11980 KB Output is correct
11 Correct 200 ms 11892 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 404 KB Output is correct
2 Execution timed out 1091 ms 412 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 12752 KB Output is correct
2 Correct 182 ms 12668 KB Output is correct
3 Correct 206 ms 12732 KB Output is correct
4 Correct 134 ms 7320 KB Output is correct
5 Correct 176 ms 9292 KB Output is correct
6 Correct 171 ms 12688 KB Output is correct
7 Correct 192 ms 12780 KB Output is correct
8 Correct 176 ms 12772 KB Output is correct
9 Correct 263 ms 13064 KB Output is correct
10 Execution timed out 1084 ms 468 KB Time limit exceeded
11 Halted 0 ms 0 KB -