Submission #201736

# Submission time Handle Problem Language Result Execution time Memory
201736 2020-02-11T21:17:33 Z nikolapesic2802 Collecting Stamps 3 (JOI20_ho_t3) C++14
25 / 100
98 ms 67960 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]));
}
int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	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]);
	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-1,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);
				}
			}
		}
	}
	printf("%i\n",sol);
	return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:40: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:42: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:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%i",&t[i]);
   ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67576 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 41 ms 67884 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 48 ms 67836 KB Output is correct
8 Correct 41 ms 67832 KB Output is correct
9 Correct 41 ms 67708 KB Output is correct
10 Correct 40 ms 67704 KB Output is correct
11 Correct 41 ms 67704 KB Output is correct
12 Correct 42 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 41 ms 67704 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 40 ms 67704 KB Output is correct
17 Correct 40 ms 67832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67576 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 41 ms 67884 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 48 ms 67836 KB Output is correct
8 Correct 41 ms 67832 KB Output is correct
9 Correct 41 ms 67708 KB Output is correct
10 Correct 40 ms 67704 KB Output is correct
11 Correct 41 ms 67704 KB Output is correct
12 Correct 42 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 41 ms 67704 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 40 ms 67704 KB Output is correct
17 Correct 40 ms 67832 KB Output is correct
18 Correct 41 ms 67704 KB Output is correct
19 Correct 42 ms 67832 KB Output is correct
20 Correct 42 ms 67704 KB Output is correct
21 Correct 42 ms 67704 KB Output is correct
22 Correct 41 ms 67704 KB Output is correct
23 Correct 43 ms 67704 KB Output is correct
24 Correct 41 ms 67704 KB Output is correct
25 Correct 41 ms 67704 KB Output is correct
26 Correct 41 ms 67704 KB Output is correct
27 Correct 42 ms 67704 KB Output is correct
28 Correct 40 ms 67704 KB Output is correct
29 Correct 42 ms 67704 KB Output is correct
30 Correct 41 ms 67704 KB Output is correct
31 Correct 41 ms 67708 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 67704 KB Output is correct
35 Correct 41 ms 67704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67576 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 41 ms 67884 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 48 ms 67836 KB Output is correct
8 Correct 41 ms 67832 KB Output is correct
9 Correct 41 ms 67708 KB Output is correct
10 Correct 40 ms 67704 KB Output is correct
11 Correct 41 ms 67704 KB Output is correct
12 Correct 42 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 41 ms 67704 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 40 ms 67704 KB Output is correct
17 Correct 40 ms 67832 KB Output is correct
18 Correct 76 ms 67832 KB Output is correct
19 Correct 58 ms 67704 KB Output is correct
20 Correct 48 ms 67704 KB Output is correct
21 Correct 57 ms 67704 KB Output is correct
22 Correct 63 ms 67832 KB Output is correct
23 Correct 64 ms 67704 KB Output is correct
24 Correct 45 ms 67832 KB Output is correct
25 Correct 45 ms 67704 KB Output is correct
26 Correct 42 ms 67704 KB Output is correct
27 Correct 48 ms 67704 KB Output is correct
28 Correct 44 ms 67704 KB Output is correct
29 Correct 48 ms 67704 KB Output is correct
30 Correct 50 ms 67832 KB Output is correct
31 Correct 46 ms 67836 KB Output is correct
32 Correct 43 ms 67704 KB Output is correct
33 Correct 46 ms 67704 KB Output is correct
34 Correct 42 ms 67708 KB Output is correct
35 Correct 47 ms 67704 KB Output is correct
36 Correct 45 ms 67836 KB Output is correct
37 Correct 48 ms 67832 KB Output is correct
38 Correct 43 ms 67704 KB Output is correct
39 Correct 46 ms 67704 KB Output is correct
40 Correct 43 ms 67704 KB Output is correct
41 Correct 98 ms 67704 KB Output is correct
42 Correct 66 ms 67960 KB Output is correct
43 Correct 91 ms 67704 KB Output is correct
44 Correct 65 ms 67704 KB Output is correct
45 Correct 91 ms 67700 KB Output is correct
46 Correct 67 ms 67704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 67576 KB Output is correct
2 Correct 41 ms 67704 KB Output is correct
3 Correct 41 ms 67704 KB Output is correct
4 Correct 41 ms 67884 KB Output is correct
5 Correct 40 ms 67704 KB Output is correct
6 Correct 40 ms 67704 KB Output is correct
7 Correct 48 ms 67836 KB Output is correct
8 Correct 41 ms 67832 KB Output is correct
9 Correct 41 ms 67708 KB Output is correct
10 Correct 40 ms 67704 KB Output is correct
11 Correct 41 ms 67704 KB Output is correct
12 Correct 42 ms 67832 KB Output is correct
13 Correct 40 ms 67704 KB Output is correct
14 Correct 41 ms 67704 KB Output is correct
15 Correct 41 ms 67832 KB Output is correct
16 Correct 40 ms 67704 KB Output is correct
17 Correct 40 ms 67832 KB Output is correct
18 Correct 41 ms 67704 KB Output is correct
19 Correct 42 ms 67832 KB Output is correct
20 Correct 42 ms 67704 KB Output is correct
21 Correct 42 ms 67704 KB Output is correct
22 Correct 41 ms 67704 KB Output is correct
23 Correct 43 ms 67704 KB Output is correct
24 Correct 41 ms 67704 KB Output is correct
25 Correct 41 ms 67704 KB Output is correct
26 Correct 41 ms 67704 KB Output is correct
27 Correct 42 ms 67704 KB Output is correct
28 Correct 40 ms 67704 KB Output is correct
29 Correct 42 ms 67704 KB Output is correct
30 Correct 41 ms 67704 KB Output is correct
31 Correct 41 ms 67708 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 67704 KB Output is correct
35 Correct 41 ms 67704 KB Output is correct
36 Correct 76 ms 67832 KB Output is correct
37 Correct 58 ms 67704 KB Output is correct
38 Correct 48 ms 67704 KB Output is correct
39 Correct 57 ms 67704 KB Output is correct
40 Correct 63 ms 67832 KB Output is correct
41 Correct 64 ms 67704 KB Output is correct
42 Correct 45 ms 67832 KB Output is correct
43 Correct 45 ms 67704 KB Output is correct
44 Correct 42 ms 67704 KB Output is correct
45 Correct 48 ms 67704 KB Output is correct
46 Correct 44 ms 67704 KB Output is correct
47 Correct 48 ms 67704 KB Output is correct
48 Correct 50 ms 67832 KB Output is correct
49 Correct 46 ms 67836 KB Output is correct
50 Correct 43 ms 67704 KB Output is correct
51 Correct 46 ms 67704 KB Output is correct
52 Correct 42 ms 67708 KB Output is correct
53 Correct 47 ms 67704 KB Output is correct
54 Correct 45 ms 67836 KB Output is correct
55 Correct 48 ms 67832 KB Output is correct
56 Correct 43 ms 67704 KB Output is correct
57 Correct 46 ms 67704 KB Output is correct
58 Correct 43 ms 67704 KB Output is correct
59 Correct 98 ms 67704 KB Output is correct
60 Correct 66 ms 67960 KB Output is correct
61 Correct 91 ms 67704 KB Output is correct
62 Correct 65 ms 67704 KB Output is correct
63 Correct 91 ms 67700 KB Output is correct
64 Correct 67 ms 67704 KB Output is correct
65 Correct 93 ms 67960 KB Output is correct
66 Correct 78 ms 67704 KB Output is correct
67 Correct 75 ms 67708 KB Output is correct
68 Correct 71 ms 67804 KB Output is correct
69 Correct 86 ms 67704 KB Output is correct
70 Correct 80 ms 67708 KB Output is correct
71 Correct 82 ms 67704 KB Output is correct
72 Correct 81 ms 67704 KB Output is correct
73 Correct 76 ms 67704 KB Output is correct
74 Correct 73 ms 67832 KB Output is correct
75 Correct 79 ms 67704 KB Output is correct
76 Correct 95 ms 67800 KB Output is correct
77 Correct 88 ms 67704 KB Output is correct
78 Incorrect 82 ms 67708 KB Output isn't correct
79 Halted 0 ms 0 KB -