답안 #940358

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
940358 2024-03-07T08:28:11 Z andrei_boaca Sightseeing in Kyoto (JOI22_kyoto) C++17
0 / 100
3 ms 10844 KB
#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],dp[100005][1005];
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;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>A[i];
    for(int i=1;i<=m;i++)
        cin>>B[i];
    ll minim=INF;
    for(int i=n;i>=1;i--)
        lins.push_back(i);
    minim=INF;
    for(int i=m;i>=1;i--)
    {
        if(i==1)
            cols.push_back(i);
        else
        {
            if(B[i]<minim)
            {
                minim=B[i];
                cols.push_back(i);
            }
        }
    }
    reverse(lins.begin(),lins.end());
    reverse(cols.begin(),cols.end());
    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];
    lins.clear();
    cols.clear();
    minim=INF;
    for(int i=n;i>=1;i--)
    {
        if(i==1)
            lins.push_back(i);
        else
        {
            if(A[i]<minim)
            {
                minim=A[i];
                lins.push_back(i);
            }
        }
    }
    minim=INF;
    for(int j=m;j>=1;j--)
        cols.push_back(j);
    reverse(lins.begin(),lins.end());
    reverse(cols.begin(),cols.end());
    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]));
            }
    ans=min(ans,dp[(int)lins.size()-1][(int)cols.size()-1]);
    cout<<ans;
    return 0;
}

Compilation message

kyoto.cpp: In function 'int main()':
kyoto.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for(int i=0;i<lins.size();i++)
      |                 ~^~~~~~~~~~~~
kyoto.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for(int j=0;j<cols.size();j++)
      |                     ~^~~~~~~~~~~~
kyoto.cpp:84:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for(int i=0;i<lins.size();i++)
      |                 ~^~~~~~~~~~~~
kyoto.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |         for(int j=0;j<cols.size();j++)
      |                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 4724 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Incorrect 2 ms 10844 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Incorrect 2 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 3 ms 4724 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 4700 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Incorrect 2 ms 10844 KB Output isn't correct
10 Halted 0 ms 0 KB -