| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 480275 | Jarif_Rahman | Patkice II (COCI21_patkice2) | C++17 | 1118 ms | 413592 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll inf = 1e18;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<str> s(n);
for(str &ss: s) cin >> ss;
vector<vector<pair<int, ll>>> v(n*m);
int ss, ee;
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
if(s[i][j] == 'o') ss = i*m + j;
if(s[i][j] == 'x') ee = i*m + j;
}
for(int i = 0; i < n; i++) for(int j = 0; j < m; j++){
if(j != 0){
v[i*m + j].pb({i*m + j - 1, s[i][j] != '<' && s[i][j] != 'o'});
}
if(j != m-1){
v[i*m + j].pb({i*m + j + 1, s[i][j] != '>' && s[i][j] != 'o'});
}
if(i != 0){
v[i*m + j].pb({(i-1)*m + j, s[i][j] != '^' && s[i][j] != 'o'});
}
if(i != n-1){
v[i*m + j].pb({(i+1)*m + j, s[i][j] != 'v' && s[i][j] != 'o'});
}
}
vector<ll> dis(n*m, inf);
deque<pair<int, int>> d;
vector<int> ls(n*m, -1);
vector<bool> bl(n*m, 0);
dis[ss] = 0;
d.pb({ss, -1});
while(!d.empty()){
auto [nd, lss] = d.back(); d.pop_back();
if(bl[nd]) continue;
bl[nd] = 1;
ls[nd] = lss;
for(auto p: v[nd]) if(dis[nd] + p.sc < dis[p.f]){
dis[p.f] = dis[nd] + p.sc;
ls[p.f] = nd;
if(p.sc == 0) d.pb({p.f, nd});
else d.push_front({p.f, nd});
}
}
int nd = ee;
while(1){
int x = ls[nd];
int a = x/m, b = x%m;
if(x == ss || x == -1) break;
if(x == nd-1) s[a][b] = '>';
if(x == nd+1) s[a][b] = '<';
if(x == nd-m) s[a][b] = 'v';
if(x == nd+m) s[a][b] = '^';
nd = x;
}
cout << dis[ee] << "\n";
for(str x: s) cout << x << "\n";
}컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
