Submission #1034022

# Submission time Handle Problem Language Result Execution time Memory
1034022 2024-07-25T08:52:02 Z DucNguyen2007 Jakarta Skyscrapers (APIO15_skyscraper) C++14
10 / 100
9 ms 16104 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e4+5;
const ll inf=2e18;
int n,m,b[maxN+1],p[maxN+1];
namespace sub2
{
    int d[2001][2001];
    struct node
    {
        int u,power;
    };
    queue<node> q;
    void solve()
    {
        memset(d,-1,sizeof(d));
        q.push({b[0],p[0]});
        d[b[0]][p[0]]=0;
        ll dem=0;
        while(!q.empty())
        {
            node tmp=q.front();
            q.pop();
            int u=tmp.u,power=tmp.power;
            //cout<<u<<" "<<power<<'\n';
            if(u==b[1])
            {
                cout<<d[u][power];
                return;
            }
            if(u+power<m)
            {
                if(d[u+power][power]==-1)
                {
                    d[u+power][power]=d[u][power]+1;
                    q.push({u+power,power});
                }
            }
            if(u-power>=0)
            {
                if(d[u-power][power]==-1)
                {
                    d[u-power][power]=d[u][power]+1;
                    q.push({u-power,power});
                }
            }
            for(int i=0;i<n;i++)
            {
                if(u+power<m&&b[i]==u+power)
                {
                   if(d[u+power][p[i]]==-1)
                   {
                       d[u+power][p[i]]=d[u][power]+1;
                       q.push({u+power,p[i]});
                   }
                }
                if(u-power>=0&&b[i]==u-power)
                {
                    if(d[u-power][p[i]]==-1)
                    {
                        d[u-power][p[i]]=d[u][power]+1;
                        q.push({u-power,p[i]});
                    }
                }
            }
        }
        cout<<-1;
    }
}
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>m>>n;
    for(int i=0;i<n;i++)
    {
        cin>>b[i]>>p[i];
    }
    sub2::solve();
}

Compilation message

skyscraper.cpp: In function 'void sub2::solve()':
skyscraper.cpp:23:12: warning: unused variable 'dem' [-Wunused-variable]
   23 |         ll dem=0;
      |            ^~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16104 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 16068 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15964 KB Output is correct
2 Correct 6 ms 15960 KB Output is correct
3 Correct 9 ms 15964 KB Output is correct
4 Correct 6 ms 15996 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15924 KB Output is correct
8 Correct 7 ms 16048 KB Output is correct
9 Correct 6 ms 15964 KB Output is correct
10 Correct 7 ms 15964 KB Output is correct
11 Incorrect 8 ms 15964 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15960 KB Output is correct
2 Correct 6 ms 15964 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15960 KB Output is correct
6 Correct 6 ms 15960 KB Output is correct
7 Correct 7 ms 15960 KB Output is correct
8 Correct 6 ms 15960 KB Output is correct
9 Correct 6 ms 16076 KB Output is correct
10 Correct 7 ms 15972 KB Output is correct
11 Incorrect 8 ms 15964 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15964 KB Output is correct
2 Correct 7 ms 15964 KB Output is correct
3 Correct 6 ms 15976 KB Output is correct
4 Correct 6 ms 15964 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 15964 KB Output is correct
8 Correct 6 ms 15900 KB Output is correct
9 Correct 6 ms 15960 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
11 Incorrect 9 ms 15964 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 15964 KB Output is correct
2 Correct 6 ms 16000 KB Output is correct
3 Correct 6 ms 15964 KB Output is correct
4 Correct 7 ms 16052 KB Output is correct
5 Correct 6 ms 15964 KB Output is correct
6 Correct 6 ms 15964 KB Output is correct
7 Correct 6 ms 16068 KB Output is correct
8 Correct 6 ms 16052 KB Output is correct
9 Correct 6 ms 15960 KB Output is correct
10 Correct 6 ms 15964 KB Output is correct
11 Incorrect 8 ms 15964 KB Output isn't correct
12 Halted 0 ms 0 KB -