답안 #201738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201738 2020-02-11T21:22:12 Z nikolapesic2802 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
99 ms 67940 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";
#define ld long double

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

const int N=205,oo=INT_MAX/2;
int dp[N][N][N][2],n,l,x[N+2],t[N+2];
int getDist(int a,int b){
	return min(abs(x[a]-x[b]),l-abs(x[a]-x[b]));
}
void input(){
	scanf("%i %i",&n,&l);
	for(int i=1;i<=n;i++)
		scanf("%i",&x[i]);
	for(int i=1;i<=n;i++)
		scanf("%i",&t[i]);
}
int solve(){
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)for(int k=0;k<N;k++)dp[i][j][k][0]=dp[i][j][k][1]=oo;
	dp[0][0][0][0]=dp[0][0][0][1]=0;
	int sol=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			for(int k=0;k<=n;k++){
				for(int o=0;o<2;o++){
					if(i+j>n||k>i+j||(i==0&&j==0)||(o==0&&i==0)||(o==1&&j==0))
						continue;
					if(o==0){ //left
						int time0,time1,time;
						if(k){
							time0=dp[i-1][j][k-1][0]+getDist(n-i+2,n-i+1),time1=dp[i-1][j][k-1][1]+getDist(j,n-i+1);  //Uzmi trenutni
							time=min(time0,time1);
							if(time<=t[n-i+1])
								dp[i][j][k][o]=time;
						}
						time0=dp[i-1][j][k][0]+getDist(n-i+2,n-i+1),time1=dp[i-1][j][k][1]+getDist(j,n-i+1);  //Nemoj uzeti trenuti
						time=min(time0,time1);
						dp[i][j][k][o]=min(dp[i][j][k][o],time);
					}
					else{ //right
						int time0,time1,time;
						if(k){
							time0=dp[i][j-1][k-1][0]+getDist(n-i+1,j),time1=dp[i][j-1][k-1][1]+getDist(j-1,j);  //Uzmi trenutni
							time=min(time0,time1);
							if(time<=t[j])
								dp[i][j][k][o]=time;
						}
						time0=dp[i][j-1][k][0]+getDist(n-i+1,j),time1=dp[i][j-1][k][1]+getDist(j-1,j);  //Nemoj uzeti trenuti
						time=min(time0,time1);
						dp[i][j][k][o]=min(dp[i][j][k][o],time);
					}
					if(dp[i][j][k][o]<oo)
						sol=max(sol,k);
				}
			}
		}
	}
	return sol;
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	input();
	printf("%i\n",solve());
	return 0;
}

Compilation message

ho_t3.cpp: In function 'void input()':
ho_t3.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&l);
  ~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i",&x[i]);
   ~~~~~^~~~~~~~~~~~
ho_t3.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i",&t[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 67704 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 45 ms 67704 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 49 ms 67832 KB Output is correct
8 Correct 40 ms 67704 KB Output is correct
9 Correct 40 ms 67704 KB Output is correct
10 Correct 39 ms 67704 KB Output is correct
11 Correct 41 ms 67832 KB Output is correct
12 Correct 40 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 40 ms 67832 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 39 ms 67704 KB Output is correct
17 Correct 40 ms 67704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 67704 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 45 ms 67704 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 49 ms 67832 KB Output is correct
8 Correct 40 ms 67704 KB Output is correct
9 Correct 40 ms 67704 KB Output is correct
10 Correct 39 ms 67704 KB Output is correct
11 Correct 41 ms 67832 KB Output is correct
12 Correct 40 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 40 ms 67832 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 39 ms 67704 KB Output is correct
17 Correct 40 ms 67704 KB Output is correct
18 Correct 40 ms 67704 KB Output is correct
19 Correct 41 ms 67708 KB Output is correct
20 Correct 40 ms 67704 KB Output is correct
21 Correct 41 ms 67704 KB Output is correct
22 Correct 40 ms 67704 KB Output is correct
23 Correct 41 ms 67704 KB Output is correct
24 Correct 43 ms 67704 KB Output is correct
25 Correct 41 ms 67704 KB Output is correct
26 Correct 39 ms 67708 KB Output is correct
27 Correct 40 ms 67704 KB Output is correct
28 Correct 41 ms 67704 KB Output is correct
29 Correct 41 ms 67704 KB Output is correct
30 Correct 42 ms 67704 KB Output is correct
31 Correct 41 ms 67832 KB Output is correct
32 Correct 44 ms 67832 KB Output is correct
33 Correct 42 ms 67832 KB Output is correct
34 Correct 40 ms 67772 KB Output is correct
35 Correct 40 ms 67704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 67704 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 45 ms 67704 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 49 ms 67832 KB Output is correct
8 Correct 40 ms 67704 KB Output is correct
9 Correct 40 ms 67704 KB Output is correct
10 Correct 39 ms 67704 KB Output is correct
11 Correct 41 ms 67832 KB Output is correct
12 Correct 40 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 40 ms 67832 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 39 ms 67704 KB Output is correct
17 Correct 40 ms 67704 KB Output is correct
18 Correct 87 ms 67704 KB Output is correct
19 Correct 61 ms 67832 KB Output is correct
20 Correct 50 ms 67832 KB Output is correct
21 Correct 55 ms 67704 KB Output is correct
22 Correct 66 ms 67708 KB Output is correct
23 Correct 46 ms 67708 KB Output is correct
24 Correct 44 ms 67832 KB Output is correct
25 Correct 47 ms 67832 KB Output is correct
26 Correct 44 ms 67704 KB Output is correct
27 Correct 46 ms 67704 KB Output is correct
28 Correct 47 ms 67704 KB Output is correct
29 Correct 47 ms 67704 KB Output is correct
30 Correct 49 ms 67704 KB Output is correct
31 Correct 51 ms 67704 KB Output is correct
32 Correct 44 ms 67704 KB Output is correct
33 Correct 45 ms 67704 KB Output is correct
34 Correct 42 ms 67704 KB Output is correct
35 Correct 47 ms 67704 KB Output is correct
36 Correct 44 ms 67704 KB Output is correct
37 Correct 48 ms 67704 KB Output is correct
38 Correct 45 ms 67832 KB Output is correct
39 Correct 48 ms 67704 KB Output is correct
40 Correct 44 ms 67704 KB Output is correct
41 Correct 92 ms 67704 KB Output is correct
42 Correct 71 ms 67704 KB Output is correct
43 Correct 91 ms 67832 KB Output is correct
44 Correct 66 ms 67748 KB Output is correct
45 Correct 91 ms 67704 KB Output is correct
46 Correct 69 ms 67704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 67704 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 45 ms 67704 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 49 ms 67832 KB Output is correct
8 Correct 40 ms 67704 KB Output is correct
9 Correct 40 ms 67704 KB Output is correct
10 Correct 39 ms 67704 KB Output is correct
11 Correct 41 ms 67832 KB Output is correct
12 Correct 40 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 40 ms 67832 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 39 ms 67704 KB Output is correct
17 Correct 40 ms 67704 KB Output is correct
18 Correct 40 ms 67704 KB Output is correct
19 Correct 41 ms 67708 KB Output is correct
20 Correct 40 ms 67704 KB Output is correct
21 Correct 41 ms 67704 KB Output is correct
22 Correct 40 ms 67704 KB Output is correct
23 Correct 41 ms 67704 KB Output is correct
24 Correct 43 ms 67704 KB Output is correct
25 Correct 41 ms 67704 KB Output is correct
26 Correct 39 ms 67708 KB Output is correct
27 Correct 40 ms 67704 KB Output is correct
28 Correct 41 ms 67704 KB Output is correct
29 Correct 41 ms 67704 KB Output is correct
30 Correct 42 ms 67704 KB Output is correct
31 Correct 41 ms 67832 KB Output is correct
32 Correct 44 ms 67832 KB Output is correct
33 Correct 42 ms 67832 KB Output is correct
34 Correct 40 ms 67772 KB Output is correct
35 Correct 40 ms 67704 KB Output is correct
36 Correct 87 ms 67704 KB Output is correct
37 Correct 61 ms 67832 KB Output is correct
38 Correct 50 ms 67832 KB Output is correct
39 Correct 55 ms 67704 KB Output is correct
40 Correct 66 ms 67708 KB Output is correct
41 Correct 46 ms 67708 KB Output is correct
42 Correct 44 ms 67832 KB Output is correct
43 Correct 47 ms 67832 KB Output is correct
44 Correct 44 ms 67704 KB Output is correct
45 Correct 46 ms 67704 KB Output is correct
46 Correct 47 ms 67704 KB Output is correct
47 Correct 47 ms 67704 KB Output is correct
48 Correct 49 ms 67704 KB Output is correct
49 Correct 51 ms 67704 KB Output is correct
50 Correct 44 ms 67704 KB Output is correct
51 Correct 45 ms 67704 KB Output is correct
52 Correct 42 ms 67704 KB Output is correct
53 Correct 47 ms 67704 KB Output is correct
54 Correct 44 ms 67704 KB Output is correct
55 Correct 48 ms 67704 KB Output is correct
56 Correct 45 ms 67832 KB Output is correct
57 Correct 48 ms 67704 KB Output is correct
58 Correct 44 ms 67704 KB Output is correct
59 Correct 92 ms 67704 KB Output is correct
60 Correct 71 ms 67704 KB Output is correct
61 Correct 91 ms 67832 KB Output is correct
62 Correct 66 ms 67748 KB Output is correct
63 Correct 91 ms 67704 KB Output is correct
64 Correct 69 ms 67704 KB Output is correct
65 Correct 83 ms 67704 KB Output is correct
66 Correct 76 ms 67836 KB Output is correct
67 Correct 79 ms 67704 KB Output is correct
68 Correct 70 ms 67704 KB Output is correct
69 Correct 79 ms 67704 KB Output is correct
70 Correct 80 ms 67704 KB Output is correct
71 Correct 78 ms 67704 KB Output is correct
72 Correct 83 ms 67704 KB Output is correct
73 Correct 76 ms 67832 KB Output is correct
74 Correct 73 ms 67832 KB Output is correct
75 Correct 77 ms 67704 KB Output is correct
76 Correct 90 ms 67940 KB Output is correct
77 Correct 89 ms 67832 KB Output is correct
78 Correct 74 ms 67704 KB Output is correct
79 Correct 75 ms 67704 KB Output is correct
80 Correct 85 ms 67704 KB Output is correct
81 Correct 77 ms 67832 KB Output is correct
82 Correct 82 ms 67704 KB Output is correct
83 Correct 96 ms 67832 KB Output is correct
84 Correct 85 ms 67704 KB Output is correct
85 Correct 85 ms 67808 KB Output is correct
86 Correct 90 ms 67704 KB Output is correct
87 Correct 76 ms 67704 KB Output is correct
88 Correct 92 ms 67704 KB Output is correct
89 Correct 99 ms 67704 KB Output is correct
90 Correct 77 ms 67704 KB Output is correct
91 Correct 92 ms 67892 KB Output is correct
92 Correct 93 ms 67704 KB Output is correct
93 Correct 84 ms 67704 KB Output is correct