Submission #976323

#TimeUsernameProblemLanguageResultExecution timeMemory
976323stefanopulosNetrpeljivost (COI23_netrpeljivost)C++17
100 / 100
513 ms91148 KiB
#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <bits/stdc++.h> using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ldb; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef pair<ldb,ldb> pdd; #define ff(i,a,b) for(int i = a; i <= b; i++) #define fb(i,b,a) for(int i = b; i >= a; i--) #define trav(a,x) for(auto& a : x) #define sz(a) (int)(a).size() #define fi first #define se second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // os.order_of_key(k) the number of elements in the os less than k // *os.find_by_order(k) print the k-th smallest number in os(0-based) const int mod = 1000000007; const ll inf = 1e15 + 5; const int mxN = 2050; int n; int mat[mxN][mxN]; ll dp[mxN][mxN]; pii seg[4 * mxN]; int poz[4 * mxN]; void calc(int v, int tl, int tr){ seg[v] = {tl, tr}; if(tl == tr){ poz[tl] = v; return; } int mid = (tl + tr) / 2; calc(v * 2, tl, mid); calc(v * 2 + 1, mid + 1, tr); } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n; ff(i,0,n - 1)ff(j,0,n - 1)cin >> mat[i][j]; calc(1,0,n - 1); ff(i,0,n)ff(a,0,n)dp[i][a] = inf; ff(a,0,n - 1)dp[0][a] = 0; ff(i,1,n - 1){ int X = 0; ff(j,0,11){ if((i >> j) & 1){ X = j; break; } } ff(a,0,n - 1){ int pos = poz[a]; pos >>= X; int L = seg[pos ^ 1].fi; int R = seg[pos ^ 1].se; ff(b,L,R){ dp[i][a] = min(dp[i][a], dp[i - 1][b] + mat[a][b]); } } } ll rez = inf; ff(a,0,n - 1)rez = min(rez, dp[n - 1][a]); cout << rez << '\n'; return 0; } /* // probati bojenje sahovski */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...