# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552891 | 2022-04-24T09:18:32 Z | M_W | Skyscraper (JOI16_skyscraper) | C++14 | 2000 ms | 304 KB |
#include <bits/stdc++.h> using namespace std; bool vis[102]; set<int> s; int a[102]; int N, L, ans = 0; void sol(int idx, int sm, int old){ if(idx > N && sm <= L){ ans++; return; } if(idx > 1){ int tmp = sm; auto it1 = s.begin(); auto it2 = s.end(); it2--; tmp += min(abs(a[old] - *it1), abs(a[old] - *it2)); if(s.size() > 1) tmp += abs(*it2 - *it1); if(tmp > L) return; } for(int i = 1; i <= N; i++){ if(vis[i]) continue; vis[i] = true; s.erase(a[i]); sol(idx + 1, sm + abs((old == -1 ? a[i] : a[old]) - a[i]), i); s.insert(a[i]); vis[i] = false; } } int main(){ scanf("%d %d", &N, &L); for(int i = 1; i <= N; i++){ scanf("%d", &a[i]); s.insert(a[i]); } sort(a + 1, a + N + 1); sol(1, 0, -1); printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 304 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 304 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 8 ms | 300 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 7 ms | 296 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2088 ms | 212 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 304 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 304 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 8 ms | 300 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 7 ms | 296 KB | Output is correct |
11 | Execution timed out | 2088 ms | 212 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |