이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include "jumps.h"
using namespace std ;
bool flag1, flag2, flag3 ;
int pw[2001], dist[2001][2001], mn[2001][2001][11] ;
vector<int> gr[2001] ;
void bfs(int city)
{
for(int i = 0 ; i < 2000 ; i++)
dist[city][i] = 1e9 ;
deque<int> d ;
d.push_back(city) ;
dist[city][city] = 0 ;
while(d.size())
{
int num = d[0] ;
d.pop_front() ;
for(int i : gr[num])
{
if(dist[city][i] != 1e9)continue ;
dist[city][i] = dist[city][num] + 1 ;
d.push_back(i) ;
}
}
}
void build_sparce_table(int city)
{
for(int i = 2 ; i <= 2000 ; i++)
pw[i] = pw[i / 2] + 1 ;
for(int i = 0 ; i < 2000 ; i++)
mn[city][i][0] = dist[city][i] ;
for(int i = 1 ; i < 11 ; i++)
for(int j = 0 ; j <= 2000 - (1 << i) ; j++)
mn[city][j][i] = min(mn[city][j][i - 1], mn[city][j + (1 << (i - 1))][i - 1]) ;
}
int get_min(int l, int r, int city)
{
int num = pw[r - l + 1] ;
return min(mn[city][l][num], mn[city][r - (1 << num) + 1][num]) ;
}
void init(int n, vector<int> a)
{
for(int i = 0 ; i < n ; i++)
if(a[i] != i + 1)flag1 = 1 ;
if(n > 2000)flag2 = 1 ;
else
{
for(int i = 0 ; i < n ; i++)
{
for(int j = i - 1 ; j >= 0 ; j--)
if(a[j] > a[i])
{
gr[i].push_back(j) ;
break ;
}
for(int j = i + 1 ; j < a.size() ; j++)
if(a[j] > a[i])
{
gr[i].push_back(j) ;
break ;
}
}
for(int i = 0 ; i < n ; i++)
{
bfs(i) ;
build_sparce_table(i) ;
}
}
}
int minimum_jumps(int a, int b, int c, int d)
{
if(!flag1)
{
if(a <= c && c <= b || a <= d && d <= b || c <= a && a <= d || a <= d && d <= b)return 0 ;
if(c - b > 0)return c - b ;
else return -1 ;
}
if(!flag2)
{
int ans = 1e9 ;
for(int i = a ; i <= b ; i++)
{
ans = min(ans, get_min(c, d, i)) ;
}
if(ans == 1e9)ans = -1 ;
return ans ;
}
if(!flag3)
{
}
}
//signed main()
//{
// ios_base::sync_with_stdio( 0 ) ;
// cin.tie( 0 ) ;
// cout.tie( 0 ) ;
// int n, q ;
// cin >> n >> q ;
// vector<int> v(n) ;
// for(int i = 0 ; i < n ; i++)
// cin >> v[i] ;
// init(n, v) ;
// while(q--)
// {
// int a, b, c, d ;
// cin >> a >> b >> c >> d ;
// cout << minimum_jumps(a, b, c, d) << '\n' ;
// }
// return 0 ;
//}
컴파일 시 표준 에러 (stderr) 메시지
jumps.cpp: In function 'void init(int, std::vector<int>)':
jumps.cpp:56:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int j = i + 1 ; j < a.size() ; j++)
| ~~^~~~~~~~~~
jumps.cpp: In function 'int minimum_jumps(int, int, int, int)':
jumps.cpp:74:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
74 | if(a <= c && c <= b || a <= d && d <= b || c <= a && a <= d || a <= d && d <= b)return 0 ;
| ~~~~~~~^~~~~~~~~
jumps.cpp:74:59: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
74 | if(a <= c && c <= b || a <= d && d <= b || c <= a && a <= d || a <= d && d <= b)return 0 ;
| ~~~~~~~^~~~~~~~~
jumps.cpp:74:79: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
74 | if(a <= c && c <= b || a <= d && d <= b || c <= a && a <= d || a <= d && d <= b)return 0 ;
| ~~~~~~~^~~~~~~~~
jumps.cpp:88:8: warning: control reaches end of non-void function [-Wreturn-type]
88 | if(!flag3)
| ^~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |