#include <bits/stdc++.h>
using namespace std;
//ofstream fout("date.out");
mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
typedef long long ll;
const ll INF=1e17;
ll n,m;
ll A[100005],B[100005];
vector<vector<ll>> dp;
string dig(ll x)
{
string s;
while(x!=0)
{
s.push_back(char('0'+x%10));
x/=10;
}
while(s.size()<4)
s.push_back('0');
reverse(s.begin(),s.end());
return s;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
vector<ll> lins,cols;
ll minA=INF,minB=INF;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>A[i];
minA=min(minA,A[i]);
}
for(int i=1;i<=m;i++)
{
cin>>B[i];
minB=min(minB,B[i]);
}
ll minim=INF;
for(int i=n;i>=1;i--)
{
if(A[i]<minim)
{
lins.push_back(i);
minim=min(minim,A[i]);
}
}
minim=INF;
for(int i=m;i>=1;i--)
{
if(B[i]<minim)
{
cols.push_back(i);
minim=min(minim,B[i]);
}
}
minim=INF;
for(int i=1;i<=n;i++)
if(A[i]<minim)
{
lins.push_back(i);
minim=A[i];
}
minim=INF;
for(int i=1;i<=m;i++)
if(B[i]<minim)
{
cols.push_back(i);
minim=B[i];
}
sort(lins.begin(),lins.end());
sort(cols.begin(),cols.end());
lins.erase(unique(lins.begin(),lins.end()),lins.end());
cols.erase(unique(cols.begin(),cols.end()),cols.end());
dp.clear();
dp.resize(lins.size());
for(int i=0;i<lins.size();i++)
dp[i].resize(cols.size());
for(int i=0;i<lins.size();i++)
for(int j=0;j<cols.size();j++)
if(i!=0||j!=0)
{
dp[i][j]=INF;
if(i>0)
dp[i][j]=min(dp[i][j],dp[i-1][j]+B[cols[j]]*(lins[i]-lins[i-1]));
if(j>0)
dp[i][j]=min(dp[i][j],dp[i][j-1]+A[lins[i]]*(cols[j]-cols[j-1]));
}
ll ans=dp[(int)lins.size()-1][(int)cols.size()-1];
cout<<ans;
return 0;
}
Compilation message
kyoto.cpp: In function 'int main()':
kyoto.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=0;i<lins.size();i++)
| ~^~~~~~~~~~~~
kyoto.cpp:81:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(int i=0;i<lins.size();i++)
| ~^~~~~~~~~~~~
kyoto.cpp:82:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int j=0;j<cols.size();j++)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
9 ms |
8196 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
8284 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
428 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
5 ms |
1624 KB |
Output is correct |
5 |
Correct |
6 ms |
3164 KB |
Output is correct |
6 |
Correct |
3 ms |
604 KB |
Output is correct |
7 |
Correct |
17 ms |
2652 KB |
Output is correct |
8 |
Correct |
12 ms |
2672 KB |
Output is correct |
9 |
Correct |
18 ms |
3668 KB |
Output is correct |
10 |
Correct |
11 ms |
3416 KB |
Output is correct |
11 |
Correct |
35 ms |
34160 KB |
Output is correct |
12 |
Correct |
11 ms |
3932 KB |
Output is correct |
13 |
Correct |
12 ms |
4048 KB |
Output is correct |
14 |
Correct |
36 ms |
33628 KB |
Output is correct |
15 |
Correct |
11 ms |
2908 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
9 ms |
8196 KB |
Output is correct |
14 |
Correct |
1 ms |
484 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
8284 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
428 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
2908 KB |
Output is correct |
32 |
Correct |
5 ms |
1624 KB |
Output is correct |
33 |
Correct |
6 ms |
3164 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
17 ms |
2652 KB |
Output is correct |
36 |
Correct |
12 ms |
2672 KB |
Output is correct |
37 |
Correct |
18 ms |
3668 KB |
Output is correct |
38 |
Correct |
11 ms |
3416 KB |
Output is correct |
39 |
Correct |
35 ms |
34160 KB |
Output is correct |
40 |
Correct |
11 ms |
3932 KB |
Output is correct |
41 |
Correct |
12 ms |
4048 KB |
Output is correct |
42 |
Correct |
36 ms |
33628 KB |
Output is correct |
43 |
Correct |
11 ms |
2908 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
0 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
468 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
7 ms |
2136 KB |
Output is correct |
56 |
Correct |
0 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
3 ms |
1116 KB |
Output is correct |
59 |
Correct |
24 ms |
3924 KB |
Output is correct |
60 |
Correct |
17 ms |
3924 KB |
Output is correct |
61 |
Correct |
17 ms |
5212 KB |
Output is correct |
62 |
Correct |
20 ms |
5208 KB |
Output is correct |
63 |
Runtime error |
744 ms |
1048576 KB |
Execution killed with signal 9 |
64 |
Halted |
0 ms |
0 KB |
- |