| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 786154 | makanhulia | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 1024 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> baris[30005];
int n, m, tujuan, ans = LLONG_MAX;
void solve(int pos, int p, int count) {
// cout << pos << " " << p << " " << count << endl;
// return 0;
if (pos == tujuan) {
ans = min(count, ans);
return;
}
// while (pos >= 0 and pos < n) {
// if (pos < 0 or pos >= n) return;
// if (pos-p >= 0) solve(pos-p, p, count+1);
// if (pos+p < n) solve(pos+p, p, count+1);
int cur = pos;
int temp = 0;
while (cur-p >= 0) {
cur -= p;
temp += 1;
// cout << "cur " << cur << endl;
if (!baris[cur].empty()) {
// cout << "NOT EMPTY" << endl;
for (int i = 0; i < baris[cur].size(); i++) {
int save = baris[cur][i];
baris[cur].erase(baris[cur].begin()+i);
solve(cur, save, count+temp);
baris[cur].push_back(save);
}
}
}
cur = pos;
temp = 0;
while (cur+p < n) {
cur += p;
temp += 1;
// cout << "cur " << cur << endl;
if (!baris[cur].empty()) {
// cout << "NOT EMPTY" << endl;
for (int i = 0; i < baris[cur].size(); i++) {
int save = baris[cur][i];
baris[cur].erase(baris[cur].begin()+i);
solve(cur, save, count+temp);
baris[cur].push_back(save);
}
}
}
// }
}
signed main() {
int b, p, posstart, pstart;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> b >> p;
if (i == 0) {
posstart = b;
pstart = p;
} else {
if (i == 1) tujuan = b;
// cout << b << endl;
baris[b].push_back(p);
}
}
solve(posstart, pstart, 0);
if (ans == LLONG_MAX) cout << -1 << endl;
else cout << ans << endl;
// vector<int> a;
// a.push_back(1);
// a.push_back(2);
// for (auto i: a) cout << i << " ";
// cout << endl;
// a.erase(a.begin()+1);
// for (auto i: a) cout << i << " ";
// cout << endl;
}컴파일 시 표준 에러 (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... | ||||
