답안 #638569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
638569 2022-09-06T12:01:26 Z morasha3 Alternating Heights (CCO22_day1problem1) C++17
0 / 25
1000 ms 4388 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()
{
    int n = v.size();
    vector<int> deg(n);
    for (int a = 0; a < n; a++)
        for (int b : v[a])
            deg[b]++;

    vector<int> q; q.reserve(n);
    for (int i = 0; i < n; i++) if (deg[i] == 0) q.push_back(i);
    for (int rep = 0; rep < q.size(); rep++) {
        int c = q[rep];
        for (auto nxt : v[c]) {
            deg[nxt]--;
            if (deg[nxt] == 0)
                q.push_back(nxt);
        }
    }
    if(n>q.size())
        f=1;
}


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);
                }
                f=0;
                dfs();
                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()':
Main.cpp:20:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int rep = 0; rep < q.size(); rep++) {
      |                       ~~~~^~~~~~~~~~
Main.cpp:28:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(n>q.size())
      |        ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 3364 KB Output is correct
2 Correct 343 ms 3364 KB Output is correct
3 Correct 335 ms 3404 KB Output is correct
4 Correct 132 ms 3356 KB Output is correct
5 Correct 153 ms 3568 KB Output is correct
6 Correct 335 ms 3404 KB Output is correct
7 Correct 563 ms 3364 KB Output is correct
8 Execution timed out 1090 ms 3028 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 3456 KB Output is correct
2 Correct 231 ms 3484 KB Output is correct
3 Correct 195 ms 3348 KB Output is correct
4 Correct 133 ms 4388 KB Output is correct
5 Correct 164 ms 3536 KB Output is correct
6 Correct 202 ms 3364 KB Output is correct
7 Correct 239 ms 3480 KB Output is correct
8 Correct 262 ms 3416 KB Output is correct
9 Correct 779 ms 3864 KB Output is correct
10 Execution timed out 1096 ms 340 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Execution timed out 1088 ms 424 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 339 ms 3364 KB Output is correct
2 Correct 343 ms 3364 KB Output is correct
3 Correct 335 ms 3404 KB Output is correct
4 Correct 132 ms 3356 KB Output is correct
5 Correct 153 ms 3568 KB Output is correct
6 Correct 335 ms 3404 KB Output is correct
7 Correct 563 ms 3364 KB Output is correct
8 Execution timed out 1090 ms 3028 KB Time limit exceeded
9 Halted 0 ms 0 KB -