Submission #958953

# Submission time Handle Problem Language Result Execution time Memory
958953 2024-04-07T09:34:45 Z Amr Railway Trip (JOI17_railway_trip) C++17
5 / 100
13 ms 712 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e2+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
ll n , k , q;
ll a[N];
ll g[N][N];
ll vis[N];
void solve()
{
    cin >> n >> k >> q;
    for(int i = 1; i <= n; i++) cin >> a[i];

    for(int i = 1; i <= n ;i++)
    {
        ll mx = -1e18;
        for(int j = i; j <= n ;j++)
        {
            mx = max(mx,a[j]);
            g[i][j] = mx;
            //g[j][i] = mx;
        }
    }
    while(q--)
    {
        ll aa, b; cin >> aa >> b;
        for(int i = 1; i <= n; i++) vis[i] = 0;
        vis[b] = 1;
        for(int kk = 2; kk <= n; kk++)
        {
            for(int i = 1; i <= n; i++)
            {
                ll co = 0;
                if(vis[i]) continue;
                for(int j = 1; j <= n; j++)
                {
                    int s = i , e = j;
                    if(s>e) swap(s,e);
                    if(vis[j]!=kk-1) continue;

                    if(abs(j-i)==1||(g[s+1][e-1]<min(a[i],a[j])) )
                    {
                        co = 1;
                    }
                }
                vis[i] = co*kk;

            }
        }
        cout << vis[aa]-2 << endl;
    }
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    while(TT--)
        solve();

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 708 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 13 ms 712 KB Output is correct
6 Correct 7 ms 604 KB Output is correct
7 Correct 7 ms 708 KB Output is correct
8 Correct 7 ms 604 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 472 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -