답안 #536243

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
536243 2022-03-12T16:31:30 Z idas Coins (LMIO19_monetos) C++11
0 / 100
128 ms 241256 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);
}

// change C
const int N=70, M=310, C=5;
int 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();
    cin >> t >> n >> k1 >> k2;
    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(j, 0, mx)
        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}};
                }

//                if(dp[i-1][j][x-j]+seg[i][j]<dp[i][j+1][x]){
//                    pst[i][j][x]={i-1,j,x-j};
//                }
//                else{
//                    pst[i][j][x]={i,j+1,x};
//                }
            }
        }
    }

    int tot=0;
    FOR(i, 0, n) FOR(j, 0, n) tot+=!g[i][j];

    int ntot=(tot+C*C-1)/(C*C);

    //cout << dp[mx][0][ntot] << "\n\n";

    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++;
            }
        }
    }

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

    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);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 468 KB K = 24
2 Incorrect 2 ms 1748 KB K = 589
3 Incorrect 126 ms 241152 KB improper placement
4 Incorrect 123 ms 241208 KB improper placement
5 Incorrect 125 ms 241256 KB improper placement
6 Incorrect 128 ms 241188 KB improper placement
7 Incorrect 124 ms 241224 KB improper placement
8 Incorrect 124 ms 241216 KB improper placement
9 Incorrect 124 ms 241160 KB K = 22431
10 Incorrect 125 ms 241228 KB improper placement