# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
595463 | AdamGS | Coins (LMIO19_monetos) | C++17 | 132 ms | 146104 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=307, INF=1e9+7;
int T[LIM][LIM], tmp[LIM][LIM], pref[LIM], suf[LIM], wynik[LIM][LIM];
pair<int,int>dp[LIM][LIM], dp2[80][80][80*40];
vector<int>V;
bool zmn;
int n;
void rozwdp() {
rep(i, n+1) dp[0][i].nd=n;
rep(i, n) {
rep(j, n) pref[j+1]=T[i][j]+pref[j];
for(int j=n-1; j>=0; --j) suf[j]=1-T[i][j]+suf[j+1];
rep(j, n+1) dp[i+1][j]={dp[i][j].st+pref[j]+suf[j], j};
for(int j=n-1; j>=0; --j) dp[i+1][j]=min(dp[i+1][j], dp[i+1][j+1]);
}
int akt=0;
for(int i=n; i; --i) {
akt=dp[i][akt].nd;
V.pb(akt);
}
reverse(all(V));
}
void diag() {
rep(i, n) {
rep(j, n) cout << (j>=n-i || j<n/2 && j==n-i-1 && i+j==n-1) << " ";
cout << '\n';
}
}
void malen() {
rep(i, n+1) rep(j, n*n/2) dp2[0][i][j+1]={INF, n};
rep(i, n) {
rep(j, n) pref[j+1]=T[i][j]+pref[j];
rep(j, n+1) rep(l, n*n/2+1) dp2[i+1][j][l]={INF, n};
rep(j, n+1) rep(l, n*n/2+1-j) dp2[i+1][j][l+j]={dp2[i][j][l].st+pref[j], j};
for(int j=n-1; j>=0; --j) rep(l, n*n/2+1) dp2[i+1][j][l]=min(dp2[i+1][j][l], dp2[i+1][j+1][l]);
}
int aktp=0, akts=n*n/2;
for(int i=n; i; --i) {
aktp=dp2[i][aktp][akts].nd;
akts-=aktp;
V.pb(aktp);
}
reverse(all(V));
}
void pion() {
rep(i, n) {
rep(j, n) cout << (j>=n/2) << " ";
cout << '\n';
}
}
void poziomo() {
rep(i, n) {
rep(j, n) cout << (i>=n/2) << " ";
cout << '\n';
}
}
void skaluj() {
rep(i, n) rep(j, n) tmp[i/4][j/4]+=T[i][j];
rep(i, n) rep(j, n) T[i][j]=tmp[i][j];
n/=4;
zmn=true;
}
void wypisz() {
rep(i, n) rep(j, n) wynik[i][j]=(j>=V[i]);
if(zmn) {
int zmien=8;
rep(i, n) rep(j, n) if(zmien && wynik[i][j]) {
wynik[i][j]=0;
--zmien;
}
}
rep(i, n) {
rep(j, n) cout << wynik[i][j] << " ";
cout << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t, k1, k2;
cin >> t >> n >> k1 >> k2;
rep(i, n) rep(j, n) cin >> T[i][j];
if(t==5 || t==9 || t==10) rozwdp();
else if(t==1 || t==2) malen();
else {
skaluj();
malen();
vector<int>S;
rep(i, V.size()) rep(j, 4) S.pb(4*V[i]);
V=S;
n*=4;
}
wypisz();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |