# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
45801 | TheDarkning | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1087 ms | 32012 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
<⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>
♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
♔♕♖♗♘♙ ♚♛♜♝♞♟
˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙
**/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <time.h>
#include <map>
#include <deque>
#include <string>
#include <memory.h>
#include <set>
#include <assert.h>
#define sz(s) s.size()
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define all(s) s.begin(), s.end()
using namespace std;
const int N = 1e6 + 5;
const int inf = 1e9 + 7;
long long n, m, p, b, x, y, cnt, dp[ 2000 ][ 2000 ];
main()
{
scanf("%d%d", &n, &m);
for( int i = 1; i < 2000; i++ )
for( int j = 1; j < 2000; j++ )
dp[ i ][ j ] = inf;
for( int i = 1; i <= m; i++ )
{
scanf("%d%d", &p, &b);
p++;
if( i == 1 )
y = p;
if( i == 2 )
x = p;
cnt = 0;
for( int j = p; j <= n; j += b )
{
dp[p][ j ] = min( dp[p][ j ], cnt );
cnt++;
}
cnt = 0;
for( int j = p; j > 0; j -= b )
{
dp[p][j] = min ( dp[p][ j ], cnt );
cnt++;
}
}
for( int i = 1; i <= n; i++ )
for( int j = 1; j <= n; j++ )
for( int k = 1; k <= n; k++ )
dp[i][j] = min( dp[i][j], dp[i][k] + dp[k][j] );
for( int i = 1; i <= n; i++ )
for( int j = 1; j <= n; j++ )
for( int k = 1; k <= n; k++ )
dp[i][j] = min( dp[i][j], dp[i][k] + dp[k][j] );
if( dp[y][x] == inf )
// assert( 0 );
dp[y][x] = -1;
cout << dp[y][x];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |