답안 #595414

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
595414 2022-07-13T17:32:26 Z AdamGS Coins (LMIO19_monetos) C++17
7.35355 / 100
18 ms 1692 KB
#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;
int T[LIM][LIM], pref[LIM], suf[LIM];
pair<int,int>dp[LIM][LIM];
int n;
void rozwdp() {
  rep(i, n) 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]);
  }
  vector<int>V;
  int akt=0;
  for(int i=n; i; --i) {
    akt=dp[i][akt].nd;
    V.pb(akt);
  }
  reverse(all(V));
  int s=dp[n][0].st;
  rep(i, n) dp[0][i].nd=0;
  rep(i, n) {
    rep(j, n+1) dp[i+1][j]={dp[i][j].st+pref[j]+suf[j], j};
    rep(j, n) dp[i+1][j+1]=min(dp[i+1][j+1], dp[i+1][j]);
  }
  if(dp[n][n].st<s) {
    V.clear();
    akt=n;
    for(int i=n; i; --i) {
      akt=dp[i][akt].nd;
      V.pb(akt);
    }
    reverse(all(V));
  }
  rep(i, n) {
    rep(j, n) cout << (j>=V[i]) << " ";
    cout << '\n';
  }
}
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';
  }
}
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];
  rozwdp();
}

Compilation message

monetos.cpp: In function 'void diag()':
monetos.cpp:50:52: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   50 |     rep(j, n) cout << (j>=n-i || j<n/2 && j==n-i-1 && i+j==n-1) << " ";
      |                                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB K = 25
2 Incorrect 1 ms 468 KB K = 625
3 Failed 14 ms 1620 KB proof wrong, contact admin
4 Partially correct 12 ms 1588 KB K = 22502
5 Incorrect 13 ms 1692 KB K = 21390
6 Incorrect 12 ms 1620 KB K = 22500
7 Partially correct 12 ms 1620 KB K = 22547
8 Incorrect 11 ms 1620 KB K = 22430
9 Incorrect 12 ms 1620 KB K = 21666
10 Partially correct 18 ms 1620 KB K = 22536