# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
536387 |
2022-03-13T07:18:16 Z |
idas |
Coins (LMIO19_monetos) |
C++11 |
|
168 ms |
241240 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();
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)
// {
// if(ans[i][j]==1){
// if(i!=n-1){
// assert(ans[i+1][j]!=0);
// }
// if(j!=n-1){
// assert(ans[i][j+1]!=0);
// }
// }
// }
// }
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 |
Correct |
1 ms |
1748 KB |
K = 17 |
2 |
Correct |
61 ms |
123768 KB |
K = 576 |
3 |
Incorrect |
168 ms |
241140 KB |
improper placement |
4 |
Incorrect |
138 ms |
241160 KB |
improper placement |
5 |
Incorrect |
126 ms |
241240 KB |
improper placement |
6 |
Incorrect |
164 ms |
241124 KB |
improper placement |
7 |
Incorrect |
137 ms |
241212 KB |
improper placement |
8 |
Incorrect |
143 ms |
241152 KB |
improper placement |
9 |
Incorrect |
153 ms |
241224 KB |
improper placement |
10 |
Incorrect |
141 ms |
241124 KB |
improper placement |