Submission #536397

#TimeUsernameProblemLanguageResultExecution timeMemory
536397idasCoins (LMIO19_monetos)C++11
100 / 100
154 ms241376 KiB
#include <bits/stdc++.h> #define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr) #define FOR(i, begin, end) for(int i = (begin); i < (end); i++) #define TSTS int ttt; cin >> ttt; while(ttt--) solve() #define all(x) (x).begin(), (x).end() #define le(vec) vec[vec.size()-1] #define sz(x) ((int)((x).size())) #define pb push_back #define s second #define f first using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef map<int, int> mii; typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int INF=1e9, MOD=1e9+7, mod=998244353; const ll LINF=1e13; void setIO() { FAST_IO; } void setIO(string s) { FAST_IO; freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } const int N=70, M=310; int C=1, t, n, k1, k2, dp[N][N][N*N], sm[N][N], seg[N][N], g[M][M], ans[M][M]; pair<int, pii> pst[N][N][N*N]; int main() { //setIO("monetos.03"); setIO(); cin >> t >> n >> k1 >> k2; if(n==300) C=5; FOR(i, 0, n) FOR(j, 0, n) cin >> g[i][j]; FOR(i, 0, n) { FOR(j, 0, n) { int x=i/C, y=j/C; sm[x][y]+=g[i][j]; } } int mx=(n-1)/C+1; FOR(i, 1, mx+1) { FOR(j, 1, mx+1) { seg[j][i]+=seg[j][i-1]; seg[j][i]+=sm[i-1][j-1]; } } FOR(i, 0, mx+3) FOR(j, 0, mx+3) FOR(x, 0, mx*mx+3) dp[i][j][x]=INF; FOR(j, 0, mx+1) dp[0][j][0]=0; FOR(i, 1, mx+1) { for(int j=mx; j>=0; j--) { FOR(x, 0, mx*mx+1) { if(x-j<0) continue; dp[i][j][x]=min(dp[i-1][j][x-j]+seg[i][j], dp[i][j+1][x]); if(dp[i][j+1][x]<=dp[i-1][j][x-j]+seg[i][j]){ pst[i][j][x]={i,{j+1,x}}; } else{ pst[i][j][x]={i-1,{j,x-j}}; } } } } int tot=0; FOR(i, 0, n) FOR(j, 0, n) tot+=!g[i][j]; int ntot=(tot+C*C-1)/(C*C); int curhigh=-1; pair<int, pii> now={mx,{0,ntot}}; vi lvls; while(now.s.s!=0){ if(now.s.f>curhigh){ curhigh=now.s.f; } else{ lvls.pb(curhigh); curhigh=now.s.f; } now=pst[now.f][now.s.f][now.s.s]; } lvls.pb(curhigh); reverse(all(lvls)); assert(sz(lvls)==mx); int lst=INF, nw=0; for(auto x : lvls){ assert(x<=lst); lst=x; nw+=x; } assert(nw*C*C==tot); FOR(i, 0, n) { FOR(j, 0, n) { ans[i][j]=1; } } FOR(i, 0, mx) { FOR(ii, 0, lvls[i]*C) { FOR(j, i*C, (i+1)*C) { ans[ii][j]=0; } } } FOR(i, 0, n) { FOR(j, 0, n) { cout << ans[i][j] << " "; } cout << '\n'; } }

Compilation message (stderr)

monetos.cpp: In function 'void setIO(std::string)':
monetos.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |     freopen((s+".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
monetos.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     freopen((s+".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...