Submission #567183

# Submission time Handle Problem Language Result Execution time Memory
567183 2022-05-23T08:54:08 Z jamezzz Sightseeing in Kyoto (JOI22_kyoto) C++17
40 / 100
194 ms 45376 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;
mt19937 rng(time(0));

#define mod 1000000007

inline int add(int a,int b){
	int r=a+b;
	while(r>=mod)r-=mod;
	while(r<0)r+=mod;
	return r;
}

inline int mult(int a,int b){
	return (int)(((ll)(a*b))%mod);
}

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 200005
#define maxx 2005

int h,w,a[maxn],pa[maxn],sa[maxn],b[maxn],pb[maxn],sb[maxn];
ll memo[maxx][maxx];
vector<pll> aa,bb;

ll dp(int i,int j){
	if(i==h&&j==w)return 0;
	if(i>h||j>w)return LINF;
	if(memo[i][j]!=-1)return memo[i][j];
	return memo[i][j]=min(dp(i+1,j)+bb[j].fi*(aa[i+1].se-aa[i].se),dp(i,j+1)+aa[i].fi*(bb[j+1].se-bb[j].se));
}

int main(){
	sf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)sf("%d",&a[i]);
	for(int i=1;i<=w;++i)sf("%d",&b[i]);
	pa[0]=sa[h+1]=pb[0]=sb[w+1]=INF;
	for(int i=1;i<=h;++i)pa[i]=min(pa[i-1],a[i]);
	for(int i=h;i>=1;--i)sa[i]=min(sa[i+1],a[i]);
	for(int i=1;i<=w;++i)pb[i]=min(pb[i-1],b[i]);
	for(int i=w;i>=1;--i)sb[i]=min(sb[i+1],b[i]);
	for(int i=1;i<=h;++i)if(pa[i-1]>a[i]||a[i]<sa[i+1])aa.pb({a[i],i});
	for(int i=1;i<=w;++i)if(pb[i-1]>b[i]||b[i]<sb[i+1])bb.pb({b[i],i});
	h=aa.size()-1,w=bb.size()-1;
	aa.pb({INF,INF});bb.pb({INF,INF});
	memset(memo,-1,sizeof memo);
	/*
	for(int i=0;i<=h;++i){
		for(int j=0;j<=w;++j){
			pf("%3lld ",dp(i,j));
		}
		pf("\n");
	}
	*/
	pf("%lld\n",dp(0,0));
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:72:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |  sf("%d%d",&h,&w);
      |    ^
kyoto.cpp:73:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |  for(int i=1;i<=h;++i)sf("%d",&a[i]);
      |                         ^
kyoto.cpp:74:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |  for(int i=1;i<=w;++i)sf("%d",&b[i]);
      |                         ^
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31736 KB Output is correct
2 Correct 15 ms 31700 KB Output is correct
3 Correct 14 ms 31724 KB Output is correct
4 Correct 13 ms 31824 KB Output is correct
5 Correct 15 ms 31700 KB Output is correct
6 Correct 14 ms 31716 KB Output is correct
7 Correct 14 ms 31820 KB Output is correct
8 Correct 14 ms 31688 KB Output is correct
9 Correct 14 ms 31828 KB Output is correct
10 Correct 14 ms 31760 KB Output is correct
11 Correct 14 ms 31828 KB Output is correct
12 Correct 14 ms 31828 KB Output is correct
13 Correct 41 ms 32000 KB Output is correct
14 Correct 14 ms 31764 KB Output is correct
15 Correct 14 ms 31828 KB Output is correct
16 Correct 32 ms 31956 KB Output is correct
17 Correct 17 ms 31716 KB Output is correct
18 Correct 14 ms 31700 KB Output is correct
19 Correct 14 ms 31740 KB Output is correct
20 Correct 13 ms 31756 KB Output is correct
21 Correct 13 ms 31716 KB Output is correct
22 Correct 13 ms 31700 KB Output is correct
23 Correct 13 ms 31700 KB Output is correct
24 Correct 16 ms 31680 KB Output is correct
25 Correct 14 ms 31748 KB Output is correct
26 Correct 14 ms 31712 KB Output is correct
27 Correct 15 ms 31692 KB Output is correct
28 Correct 14 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 31780 KB Output is correct
2 Correct 14 ms 31692 KB Output is correct
3 Correct 17 ms 31984 KB Output is correct
4 Correct 28 ms 32708 KB Output is correct
5 Correct 29 ms 32852 KB Output is correct
6 Correct 17 ms 32168 KB Output is correct
7 Correct 30 ms 34132 KB Output is correct
8 Correct 30 ms 34056 KB Output is correct
9 Correct 31 ms 34124 KB Output is correct
10 Correct 33 ms 34128 KB Output is correct
11 Correct 133 ms 34452 KB Output is correct
12 Correct 34 ms 34144 KB Output is correct
13 Correct 33 ms 34160 KB Output is correct
14 Correct 153 ms 34504 KB Output is correct
15 Correct 32 ms 34080 KB Output is correct
16 Correct 13 ms 31700 KB Output is correct
17 Correct 14 ms 31700 KB Output is correct
18 Correct 14 ms 31688 KB Output is correct
19 Correct 14 ms 31700 KB Output is correct
20 Correct 14 ms 31752 KB Output is correct
21 Correct 16 ms 31700 KB Output is correct
22 Correct 14 ms 31696 KB Output is correct
23 Correct 13 ms 31700 KB Output is correct
24 Correct 15 ms 31800 KB Output is correct
25 Correct 14 ms 31692 KB Output is correct
26 Correct 14 ms 31700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31736 KB Output is correct
2 Correct 15 ms 31700 KB Output is correct
3 Correct 14 ms 31724 KB Output is correct
4 Correct 13 ms 31824 KB Output is correct
5 Correct 15 ms 31700 KB Output is correct
6 Correct 14 ms 31716 KB Output is correct
7 Correct 14 ms 31820 KB Output is correct
8 Correct 14 ms 31688 KB Output is correct
9 Correct 14 ms 31828 KB Output is correct
10 Correct 14 ms 31760 KB Output is correct
11 Correct 14 ms 31828 KB Output is correct
12 Correct 14 ms 31828 KB Output is correct
13 Correct 41 ms 32000 KB Output is correct
14 Correct 14 ms 31764 KB Output is correct
15 Correct 14 ms 31828 KB Output is correct
16 Correct 32 ms 31956 KB Output is correct
17 Correct 17 ms 31716 KB Output is correct
18 Correct 14 ms 31700 KB Output is correct
19 Correct 14 ms 31740 KB Output is correct
20 Correct 13 ms 31756 KB Output is correct
21 Correct 13 ms 31716 KB Output is correct
22 Correct 13 ms 31700 KB Output is correct
23 Correct 13 ms 31700 KB Output is correct
24 Correct 16 ms 31680 KB Output is correct
25 Correct 14 ms 31748 KB Output is correct
26 Correct 14 ms 31712 KB Output is correct
27 Correct 15 ms 31692 KB Output is correct
28 Correct 14 ms 31700 KB Output is correct
29 Correct 14 ms 31780 KB Output is correct
30 Correct 14 ms 31692 KB Output is correct
31 Correct 17 ms 31984 KB Output is correct
32 Correct 28 ms 32708 KB Output is correct
33 Correct 29 ms 32852 KB Output is correct
34 Correct 17 ms 32168 KB Output is correct
35 Correct 30 ms 34132 KB Output is correct
36 Correct 30 ms 34056 KB Output is correct
37 Correct 31 ms 34124 KB Output is correct
38 Correct 33 ms 34128 KB Output is correct
39 Correct 133 ms 34452 KB Output is correct
40 Correct 34 ms 34144 KB Output is correct
41 Correct 33 ms 34160 KB Output is correct
42 Correct 153 ms 34504 KB Output is correct
43 Correct 32 ms 34080 KB Output is correct
44 Correct 13 ms 31700 KB Output is correct
45 Correct 14 ms 31700 KB Output is correct
46 Correct 14 ms 31688 KB Output is correct
47 Correct 14 ms 31700 KB Output is correct
48 Correct 14 ms 31752 KB Output is correct
49 Correct 16 ms 31700 KB Output is correct
50 Correct 14 ms 31696 KB Output is correct
51 Correct 13 ms 31700 KB Output is correct
52 Correct 15 ms 31800 KB Output is correct
53 Correct 14 ms 31692 KB Output is correct
54 Correct 14 ms 31700 KB Output is correct
55 Correct 25 ms 32744 KB Output is correct
56 Correct 14 ms 31720 KB Output is correct
57 Correct 18 ms 31912 KB Output is correct
58 Correct 18 ms 32084 KB Output is correct
59 Correct 40 ms 34136 KB Output is correct
60 Correct 34 ms 34124 KB Output is correct
61 Correct 35 ms 34148 KB Output is correct
62 Correct 37 ms 34168 KB Output is correct
63 Incorrect 194 ms 45376 KB Output isn't correct
64 Halted 0 ms 0 KB -