이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 50;
const int MAXT = 20000;
const ll INF = 1e15;
int N, T, S, P[MAXT+10], R[MAXN+10][MAXT+10];
vector<int> V[MAXT+10];
int cnt[MAXN+10];
ll dp[MAXN+10][MAXT+10];
struct SEG
{
ll A[MAXT+10], tree[MAXT*4+10];
void init(int node, int tl, int tr)
{
if(tl==tr) { tree[node]=A[tl]; return; }
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
tree[node]=min(tree[node*2], tree[node*2+1]);
}
ll query(int node, int tl, int tr, int l, int r)
{
if(l<=tl && tr<=r) return tree[node];
if(r<tl || tr<l) return INF;
int mid=tl+tr>>1;
return min(query(node*2, tl, mid, l, r), query(node*2+1, mid+1, tr, l, r));
}
}seg;
int main()
{
int i, j, k, p;
scanf("%d%d%d", &N, &T, &S);
for(i=1; i<=T; i++) scanf("%d", &P[i]), P[i]+=P[i-1];
for(i=1; i<=N; i++) for(j=1; j<=T; j++) scanf("%1d", &R[i][j]);
for(i=1; i<=T; i++)
{
for(j=1; j<=N; j++) if(R[j][i]==0) cnt[j]=i;
for(j=1; j<=N; j++) V[i].push_back(cnt[j]);
V[i].push_back(i); V[i].push_back(0);
sort(V[i].begin(), V[i].end());
//for(j=0; j<=N+1; j++) printf("%d ", V[i][j]); printf("\n");
}
for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
for(i=1; i<=S; i++)
{
for(k=0; k<=N; k++)
{
//for(j=0; j<=T; j++) seg.A[j]=dp[i-1][j]-k*P[j];
//seg.init(1, 0, T);
for(j=1; j<=T; j++)
{
if(V[j][k]==V[j][k+1]) continue;
ll now=INF;
for(p=V[j][k]; p<V[j][k+1]; p++) now=min(now, dp[i-1][p]-k*P[p]);
dp[i][j]=min(dp[i][j], now+k*P[j]);
//dp[i][j]=min(dp[i][j], seg.query(1, 0, T, V[j][k], V[j][k+1]-1)+k*P[j]);
}
//printf("%lld ", dp[i][j]);
}
//printf("\n");
}
for(i=1; i<=S; i++) printf("%lld\n", dp[i][T]);
}
컴파일 시 표준 에러 (stderr) 메시지
popeala.cpp: In member function 'void SEG::init(int, int, int)':
popeala.cpp:24:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
popeala.cpp: In member function 'll SEG::query(int, int, int, int, int)':
popeala.cpp:34:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
popeala.cpp: In function 'int main()':
popeala.cpp:56:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
^~~
popeala.cpp:56:59: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(i=0; i<=S; i++) for(j=0; j<=T; j++) dp[i][j]=INF; dp[0][0]=0;
^~
popeala.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &N, &T, &S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
popeala.cpp:44:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=T; i++) scanf("%d", &P[i]), P[i]+=P[i-1];
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
popeala.cpp:45:50: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) for(j=1; j<=T; j++) scanf("%1d", &R[i][j]);
~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |