Submission #1013443

# Submission time Handle Problem Language Result Execution time Memory
1013443 2024-07-03T14:36:55 Z amine_aroua Nestabilnost (COI23_nestabilnost) C++17
0 / 100
1500 ms 524288 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define intt long long
#define nl '\n'
int n;
vector<int> a , f;
vector<map<int ,int>> possible_k;
vector<intt> dp;
int main() {
    cin>>n;
    a.assign(n , 0);
    f.assign(n + 1 , 0);
    for(int i = 0 ; i < n ; i++)
        cin>>a[i];
    int mn = 1e9;
    for(int i = 1 ; i <= n;i++)
    {
        cin>>f[i];
        mn = min(mn , f[i]);
    }
    for(int i = 1 ; i <= n - 1 ; i++)
    {
        int u , v;
        cin>>u>>v;
    }
    if(n == 1)
    {
        cout<<mn<<nl;
        return 0;
    }
    possible_k.assign(n , map<int ,int>());
    for(int i = 0 ; i + 1 < n ; i++)
    {
        int diff = abs(a[i] + 1 - a[i + 1]);
        vector<int> vals;
        if(diff == 0)
        {
            for(int j = 1 ; j <= n;j++)
            {
                vals.pb(j);
            }
        }
        else
        {
            for(int d = 1 ; d* d <= diff ; d++)
            {
                if(d * d == diff)
                {
                    vals.pb(d);
                }
                else if(diff % d == 0)
                {
                    vals.pb(d);
                    vals.pb(diff/d);
                }
            }
        }
        for(auto k : vals)
        {
            if(possible_k[i].count(k))
                continue;
            int last = i + 1;
            for( ; last < n && (abs(a[last - 1] - a[last] + 1) % k == 0); last++);
            for(int j = i; j < last ; j++)
            {
                possible_k[j][k] = last;
            }
        }
    }
    dp.assign(n + 1 , LLONG_MAX);
    dp[n] = 0;
    for(int i = n - 1 ; i >= 0 ; i--)
    {
        dp[i] = dp[i + 1] + mn;
        if(i + 1 < n)
        {
            for(auto [k , last] : possible_k[i])
            {
                dp[i] = min(dp[i] , dp[last] + f[k]);
            }
        }
    }
    cout<<dp[0]<<nl;
}
# Verdict Execution time Memory Grader output
1 Runtime error 1109 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 225 ms 33232 KB Output is correct
2 Execution timed out 1595 ms 401372 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1109 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1109 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -