| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 786132 | christinelynn | Jakarta Skyscrapers (APIO15_skyscraper) | C++17 | 1 ms | 980 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 <bits/stdc++.h>
using namespace std;
#define int long long
vector<int> baris[30005];
int n, m, tujuan, ans = INT_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 == INT_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;
}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... | ||||
