Submission #98726

#TimeUsernameProblemLanguageResultExecution timeMemory
98726SpeedOfMagicPopeala (CEOI16_popeala)C++17
17 / 100
2037 ms1024 KiB
/** MIT License Copyright (c) 2018-2019 Vasilev Daniil **/ #include <bits/stdc++.h> using namespace std; template<typename T> using v = vector<T>; //#define int long long typedef long double ld; typedef string str; typedef vector<int> vint; #define rep(a, l, r) for(int a = (l); a < (r); a++) #define pb push_back #define fs first #define sc second #define sz(a) ((int) a.size()) const long long inf = 4611686018427387903; //2^62 - 1 const long double EPS = 1e-10; #if 0 //FileIO const string fileName = ""; ifstream fin ((fileName == "" ? "input.txt" : fileName + ".in" )); ofstream fout((fileName == "" ? "output.txt" : fileName + ".out")); #define get fin >> #define put fout << #else #define get cin >> #define put cout << #endif #define eol put endl void read() {} template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg) ;read(args...) ;} void print(){} template<typename Arg,typename... Args> void print(Arg arg,Args... args){put (arg)<<" ";print(args...);} int getInt(){int a; get a; return a;} //code starts here void run() { int n, t, s; read(n, t, s); int pts[t]; rep(i, 0, t) get pts[i]; char res[n][t]; rep(i, 0, n) { str st; get st; rep(j, 0, t) res[i][j] = st[j] - '0'; } int dp[t][s]; rep(i, 0, t) rep(j, 0, s) dp[i][j] = 2000000001; int cur[n]; memset(cur, 0, sizeof cur); rep(i, 0, t) { rep(j, 0, n) if (res[j][i] && cur[j] != -1) cur[j] += pts[i]; else cur[j] = -1; dp[i][0] = 0; rep(j, 0, n) if (cur[j] != -1) dp[i][0] += cur[j]; } rep(j, 1, s) { rep(i, 0, t) { memset(cur, 0, sizeof cur); for (int k = i - 1; k >= 0; k--) { int sum = 0; rep(l, 0, n) { if (res[l][k + 1] && cur[l] != -1) cur[l] += pts[k + 1]; else cur[l] = -1; if (cur[l] != -1) sum += cur[l]; } dp[i][j] = min(dp[i][j], dp[k][j - 1] + sum); } } } rep(j, 0, s) put dp[t - 1][j], eol; } signed main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); put fixed << setprecision(12); run(); return 0;}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...