# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
34675 | 2017-11-14T22:43:25 Z | mohammad_kilani | 전선 연결 (IOI17_wiring) | C++14 | 1000 ms | 11836 KB |
#include "wiring.h" #include <bits/stdc++.h> using namespace std; #define red 1 #define blue 0 const int N = 200010; long long dp[N]; vector< pair<int,bool> > v; int n; long long solve(int i){ if(i == n) return 0; if(dp[i] != -1) return dp[i]; dp[i] = 1e18; int idx = -1; for(int j=i+1;j<n;j++){ if(v[j].second != v[i].second){ idx = j; break; } } if(idx == -1) return dp[i]; long long sum = 0; for(int j=i;j<idx;j++) sum += abs(v[idx].first - v[j].first); int idx2 = n; for(int j=idx+1;j<n;j++){ if(v[i].second == v[j].second){ idx2 = j; break; } } for(int j=idx;j<idx2;j++){ sum+= abs(v[j].first - v[idx].first); if(j - idx >= idx - i) sum += abs(v[idx].first - v[idx-1].first); dp[i] = min(dp[i],sum + solve(j+1)); } for(int j=idx2;j<n;j++){ if(v[j].second == v[idx].second) break; sum+= abs(v[j].first-v[idx].first); dp[i] = min(dp[i],sum + solve(j+1)); } return dp[i]; } long long min_total_length(std::vector<int> r, std::vector<int> b) { if(r.back() < b[0]){ int n =r.size() , m = b.size(); long long sum = 0 ; int idx = 0 ; int idx2 = 0; for(int i=0;i<min(n,m);i++) sum += abs(r[idx++] - b[idx2++]); for(int i=idx;i<r.size();i++) sum+= abs(r[i] - b[0]); for(int i=idx2;i<b.size();i++) sum+= abs(b[i] - r.back()); return sum; } memset(dp,-1,sizeof(dp)); int j =0 ; for(int i=0;i<r.size();i++){ while(j < b.size() && b[j] < r[i]) v.push_back(make_pair(b[j++],blue)); v.push_back(make_pair(r[i],red)); } while(j < b.size()) v.push_back(make_pair(b[j++],blue)); n = v.size(); return solve(0); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3580 KB | Output is correct |
2 | Correct | 0 ms | 3580 KB | Output is correct |
3 | Correct | 0 ms | 3580 KB | Output is correct |
4 | Correct | 0 ms | 3580 KB | Output is correct |
5 | Correct | 0 ms | 3580 KB | Output is correct |
6 | Correct | 0 ms | 3580 KB | Output is correct |
7 | Correct | 0 ms | 3580 KB | Output is correct |
8 | Correct | 0 ms | 3580 KB | Output is correct |
9 | Correct | 0 ms | 3580 KB | Output is correct |
10 | Correct | 0 ms | 3580 KB | Output is correct |
11 | Correct | 0 ms | 3580 KB | Output is correct |
12 | Correct | 0 ms | 3580 KB | Output is correct |
13 | Correct | 0 ms | 3580 KB | Output is correct |
14 | Correct | 0 ms | 3580 KB | Output is correct |
15 | Correct | 0 ms | 3580 KB | Output is correct |
16 | Correct | 0 ms | 3580 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3580 KB | Output is correct |
2 | Correct | 0 ms | 3580 KB | Output is correct |
3 | Correct | 26 ms | 4756 KB | Output is correct |
4 | Correct | 19 ms | 4756 KB | Output is correct |
5 | Correct | 23 ms | 4756 KB | Output is correct |
6 | Correct | 29 ms | 5148 KB | Output is correct |
7 | Correct | 33 ms | 5148 KB | Output is correct |
8 | Correct | 33 ms | 5148 KB | Output is correct |
9 | Correct | 36 ms | 5148 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3580 KB | Output is correct |
2 | Correct | 0 ms | 3580 KB | Output is correct |
3 | Correct | 63 ms | 11740 KB | Output is correct |
4 | Correct | 59 ms | 10280 KB | Output is correct |
5 | Correct | 0 ms | 3580 KB | Output is correct |
6 | Correct | 0 ms | 3580 KB | Output is correct |
7 | Correct | 0 ms | 3580 KB | Output is correct |
8 | Correct | 0 ms | 3580 KB | Output is correct |
9 | Correct | 0 ms | 3580 KB | Output is correct |
10 | Correct | 0 ms | 3580 KB | Output is correct |
11 | Correct | 0 ms | 3580 KB | Output is correct |
12 | Correct | 0 ms | 3580 KB | Output is correct |
13 | Correct | 0 ms | 3580 KB | Output is correct |
14 | Correct | 0 ms | 3580 KB | Output is correct |
15 | Correct | 0 ms | 3580 KB | Output is correct |
16 | Correct | 0 ms | 3580 KB | Output is correct |
17 | Correct | 0 ms | 3580 KB | Output is correct |
18 | Correct | 49 ms | 11732 KB | Output is correct |
19 | Correct | 53 ms | 11724 KB | Output is correct |
20 | Correct | 59 ms | 10276 KB | Output is correct |
21 | Correct | 49 ms | 11732 KB | Output is correct |
22 | Correct | 63 ms | 11836 KB | Output is correct |
23 | Correct | 56 ms | 11832 KB | Output is correct |
24 | Correct | 59 ms | 11836 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3580 KB | Output is correct |
2 | Execution timed out | 1000 ms | 8304 KB | Execution timed out |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 3580 KB | Output is correct |
2 | Correct | 0 ms | 3580 KB | Output is correct |
3 | Correct | 0 ms | 3580 KB | Output is correct |
4 | Correct | 0 ms | 3580 KB | Output is correct |
5 | Correct | 0 ms | 3580 KB | Output is correct |
6 | Correct | 0 ms | 3580 KB | Output is correct |
7 | Correct | 0 ms | 3580 KB | Output is correct |
8 | Correct | 0 ms | 3580 KB | Output is correct |
9 | Correct | 0 ms | 3580 KB | Output is correct |
10 | Correct | 0 ms | 3580 KB | Output is correct |
11 | Correct | 0 ms | 3580 KB | Output is correct |
12 | Correct | 0 ms | 3580 KB | Output is correct |
13 | Correct | 0 ms | 3580 KB | Output is correct |
14 | Correct | 0 ms | 3580 KB | Output is correct |
15 | Correct | 0 ms | 3580 KB | Output is correct |
16 | Correct | 0 ms | 3580 KB | Output is correct |
17 | Correct | 0 ms | 3580 KB | Output is correct |
18 | Correct | 0 ms | 3580 KB | Output is correct |
19 | Correct | 26 ms | 4756 KB | Output is correct |
20 | Correct | 19 ms | 4756 KB | Output is correct |
21 | Correct | 23 ms | 4756 KB | Output is correct |
22 | Correct | 29 ms | 5148 KB | Output is correct |
23 | Correct | 33 ms | 5148 KB | Output is correct |
24 | Correct | 33 ms | 5148 KB | Output is correct |
25 | Correct | 36 ms | 5148 KB | Output is correct |
26 | Correct | 0 ms | 3580 KB | Output is correct |
27 | Correct | 0 ms | 3580 KB | Output is correct |
28 | Correct | 63 ms | 11740 KB | Output is correct |
29 | Correct | 59 ms | 10280 KB | Output is correct |
30 | Correct | 0 ms | 3580 KB | Output is correct |
31 | Correct | 0 ms | 3580 KB | Output is correct |
32 | Correct | 0 ms | 3580 KB | Output is correct |
33 | Correct | 0 ms | 3580 KB | Output is correct |
34 | Correct | 0 ms | 3580 KB | Output is correct |
35 | Correct | 0 ms | 3580 KB | Output is correct |
36 | Correct | 0 ms | 3580 KB | Output is correct |
37 | Correct | 0 ms | 3580 KB | Output is correct |
38 | Correct | 0 ms | 3580 KB | Output is correct |
39 | Correct | 0 ms | 3580 KB | Output is correct |
40 | Correct | 0 ms | 3580 KB | Output is correct |
41 | Correct | 0 ms | 3580 KB | Output is correct |
42 | Correct | 0 ms | 3580 KB | Output is correct |
43 | Correct | 49 ms | 11732 KB | Output is correct |
44 | Correct | 53 ms | 11724 KB | Output is correct |
45 | Correct | 59 ms | 10276 KB | Output is correct |
46 | Correct | 49 ms | 11732 KB | Output is correct |
47 | Correct | 63 ms | 11836 KB | Output is correct |
48 | Correct | 56 ms | 11832 KB | Output is correct |
49 | Correct | 59 ms | 11836 KB | Output is correct |
50 | Correct | 0 ms | 3580 KB | Output is correct |
51 | Execution timed out | 1000 ms | 8304 KB | Execution timed out |
52 | Halted | 0 ms | 0 KB | - |