제출 #1069076

#제출 시각아이디문제언어결과실행 시간메모리
1069076vjudge1Knapsack (NOI18_knapsack)C++17
컴파일 에러
0 ms0 KiB
bool pro[s + 1] = {false}; pro[0] = true; map<int, int> mp; for(int x = 1; x < 2001; x++) mp[x] = s/x; vector<pii> choose; vector<iii> a; for(int x = 0; x < n; x++) { int v, w, k; cin >> v >> w >> k; a.push_back({v, w, k}); } sort(a.begin(), a.end()); for(iii t : a) { int v = get<0>(t); int w = get<1>(t); int k = get<2>(t); if(mp[w] >= k) { for(int x = 0; x < k; x++) choose.push_back({v, w}); mp[w] -= k; } else { for(int x = 0; x < mp[w]; x++) choose.push_back({v, w}); mp[w] = 0; } } int mx = 0; for(pii p : choose) { //cout << p.f << " " << p.s << "\n"; for(int x = s; x >= 0; x--) { if(x - p.s >= 0) { if(pro[x - p.s]) { pro[x] = true; dp[x] = max(dp[x], dp[x - p.s] + p.f); mx = max(mx, dp[x]); } } } } cout << mx; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); //freopen("wormsort.in", "r", stdin); //freopen("wormsort.out", "w", stdout); int t = 1; //cin >> t; while(t--) { solve(); } return 0; }

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

knapsack.cpp:1:14: error: 's' was not declared in this scope
    1 |     bool pro[s + 1] = {false};
      |              ^
knapsack.cpp:2:5: error: 'pro' does not name a type
    2 |     pro[0] = true;
      |     ^~~
knapsack.cpp:3:5: error: 'map' does not name a type
    3 |     map<int, int> mp;
      |     ^~~
knapsack.cpp:4:5: error: expected unqualified-id before 'for'
    4 |     for(int x = 1; x < 2001; x++) mp[x] = s/x;
      |     ^~~
knapsack.cpp:4:20: error: 'x' does not name a type
    4 |     for(int x = 1; x < 2001; x++) mp[x] = s/x;
      |                    ^
knapsack.cpp:4:30: error: 'x' does not name a type
    4 |     for(int x = 1; x < 2001; x++) mp[x] = s/x;
      |                              ^
knapsack.cpp:5:5: error: 'vector' does not name a type
    5 |     vector<pii> choose;
      |     ^~~~~~
knapsack.cpp:6:5: error: 'vector' does not name a type
    6 |     vector<iii> a;
      |     ^~~~~~
knapsack.cpp:7:5: error: expected unqualified-id before 'for'
    7 |     for(int x = 0; x < n; x++)
      |     ^~~
knapsack.cpp:7:20: error: 'x' does not name a type
    7 |     for(int x = 0; x < n; x++)
      |                    ^
knapsack.cpp:7:27: error: 'x' does not name a type
    7 |     for(int x = 0; x < n; x++)
      |                           ^
knapsack.cpp:12:9: error: expected constructor, destructor, or type conversion before '(' token
   12 |     sort(a.begin(), a.end());
      |         ^
knapsack.cpp:13:5: error: expected unqualified-id before 'for'
   13 |     for(iii t : a)
      |     ^~~
knapsack.cpp:30:5: error: expected unqualified-id before 'for'
   30 |     for(pii p : choose)
      |     ^~~
knapsack.cpp:46:5: error: 'cout' does not name a type
   46 |     cout << mx;
      |     ^~~~
knapsack.cpp:47:1: error: expected declaration before '}' token
   47 | }
      | ^
knapsack.cpp: In function 'int main()':
knapsack.cpp:50:5: error: 'ios_base' has not been declared
   50 |     ios_base::sync_with_stdio(0);
      |     ^~~~~~~~
knapsack.cpp:51:5: error: 'cin' was not declared in this scope
   51 |     cin.tie(0), cout.tie(0);
      |     ^~~
knapsack.cpp:51:17: error: 'cout' was not declared in this scope
   51 |     cin.tie(0), cout.tie(0);
      |                 ^~~~
knapsack.cpp:58:9: error: 'solve' was not declared in this scope
   58 |         solve();
      |         ^~~~~