Submission #536266

# Submission time Handle Problem Language Result Execution time Memory
536266 2022-03-12T16:50:33 Z idas Coins (LMIO19_monetos) C++11
0 / 100
7 ms 468 KB
#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[N][N];
pair<int, pii> pst[N][N][N*N];

int main()
{
    setIO();
    assert(1==0);
    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));

    FOR(i, 0, n)
    {
        FOR(j, 0, n)
        {
            ans[i][j]=1;
        }
    }

    int added=0;
    FOR(i, 0, mx)
    {
        FOR(j, i*C, i*C+C)
        {
            FOR(ii, 0, lvls[i]*C)
            {
                if(ii>=n||j>=n) continue;
                ans[ii][j]=0;
                added++;
            }
        }
    }

    assert(added>=tot);

    for(int i=le(lvls)*C-1; i>=le(lvls)*C-C; i--){
        for(int j=mx*C-1; j>=(mx-1)*C; j--){
            if(added==tot) break;
            added--; ans[i][j]=1;
        }
    }

    assert(added==tot);

    FOR(i, 0, n)
    {
        FOR(j, 0, n)
        {
            cout << ans[i][j] << " ";
        }
        cout << '\n';
    }
}

Compilation message

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 time Memory Grader output
1 Runtime error 6 ms 468 KB Execution killed with signal 6
2 Runtime error 6 ms 468 KB Execution killed with signal 6
3 Runtime error 6 ms 468 KB Execution killed with signal 6
4 Runtime error 6 ms 420 KB Execution killed with signal 6
5 Runtime error 6 ms 468 KB Execution killed with signal 6
6 Runtime error 6 ms 416 KB Execution killed with signal 6
7 Runtime error 6 ms 420 KB Execution killed with signal 6
8 Runtime error 6 ms 468 KB Execution killed with signal 6
9 Runtime error 7 ms 468 KB Execution killed with signal 6
10 Runtime error 6 ms 468 KB Execution killed with signal 6