Submission #595433

# Submission time Handle Problem Language Result Execution time Memory
595433 2022-07-13T18:03:13 Z AdamGS Coins (LMIO19_monetos) C++17
36.9117 / 100
24 ms 35212 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, INF=1e9+7;
int T[LIM][LIM], pref[LIM], suf[LIM];
pair<int,int>dp[LIM][LIM], dp2[57][57][57*30];
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]);
  }
  vector<int>V;
  int akt=0;
  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';
  }
}
void malen() {
  rep(i, n+1) rep(j, n*n/2) dp2[0][i][j+1].st=INF;
  rep(i, n) {
    rep(j, n) pref[j+1]=T[i][j]+pref[j];
    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;
  vector<int>V;
  for(int i=n; i; --i) {
    aktp=dp2[i][aktp][akts].nd;
    akts-=aktp;
    V.pb(aktp);
  }
  reverse(all(V));
  rep(i, n) {
    rep(j, n) cout << (j>=V[i]) << " ";
    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 diag();
}
// 1  -
// 2  -
// 3  +-
// 4  +-
// 5  +
// 6  +-
// 7  +- 
// 8  -
// 9  +
// 10 +

Compilation message

monetos.cpp: In function 'void diag()':
monetos.cpp:35:52: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   35 |     rep(j, n) cout << (j>=n-i || j<n/2 && j==n-i-1 && i+j==n-1) << " ";
      |                                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 852 KB improper placement
2 Incorrect 24 ms 35212 KB improper placement
3 Partially correct 11 ms 836 KB K = 20155
4 Partially correct 11 ms 852 KB K = 23377
5 Correct 12 ms 1592 KB K = 17065
6 Partially correct 16 ms 868 KB K = 22065
7 Partially correct 11 ms 872 KB K = 22427
8 Incorrect 16 ms 816 KB K = 22416
9 Correct 14 ms 1528 KB K = 19939
10 Correct 11 ms 1576 KB K = 18959