제출 #448743

#제출 시각아이디문제언어결과실행 시간메모리
448743CaoHuuKhuongDuyCloud Computing (CEOI18_clo)C++14
0 / 100
1 ms460 KiB
#include <iostream> #include <stdio.h> #include <algorithm> using namespace std; #define int long long const int N=4e3+1; const int oo=1e16; int f[N][1001]; struct computer { int c,f,val; }a[N]; bool compa(computer a,computer b) { if (a.f==b.f) return a.c>b.c; return a.f>b.f; } signed main() { ios::sync_with_stdio(false); cin.tie(0); //freopen("test.inp","r",stdin); int n,m; cin>>n; int sum=0; for (int i=1;i<=n;i++) { cin>>a[i].c>>a[i].f>>a[i].val; a[i].val=-a[i].val; sum+=a[i].c; } cin>>m; for (int i=n+1;i<=n+m;i++) { cin>>a[i].c>>a[i].f>>a[i].val; a[i].c=-a[i].c; } n+=m; sort(a+1,a+1+n,compa); for (int i=1;i<=n;i++) cout<<a[i].c<<" "<<a[i].f<<" "<<a[i].val<<endl; for (int i=0;i<=n;i++) for (int j=0;j<=2000;j++) f[i][j]=-oo; f[0][0]=0; int res=0; for (int i=1;i<=n;i++) for (int j=0;j<=1000;j++) { f[i][j]=f[i-1][j]; if (j-a[i].c>=0) f[i][j]=max(f[i][j],f[i-1][j-a[i].c]+a[i].val); if (i==n) res=max(res,f[i][j]); } cout<<res; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

clo.cpp: In function 'int main()':
clo.cpp:44:13: warning: iteration 1001 invokes undefined behavior [-Waggressive-loop-optimizations]
   44 |      f[i][j]=-oo;
      |      ~~~~~~~^~~~
clo.cpp:43:18: note: within this loop
   43 |    for (int j=0;j<=2000;j++)
      |                 ~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...