제출 #1068376

#제출 시각아이디문제언어결과실행 시간메모리
1068376quangminh412Detecting Molecules (IOI16_molecules)C++14
31 / 100
29 ms65536 KiB
#include <bits/stdc++.h> using namespace std; /* John Watson https://codeforces.com/profile/quangminh98 Mua Code nhu mua Florentino !! */ #define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ll long long const int oo = 1e9; vector<int> solve_1(int l, int u, vector<int> w) { vector<int> ans; int cur = 0; for (int i = 0; i < w.size(); i++) { cur += w[i]; ans.push_back(i); if (l <= cur && cur <= u) return ans; } return {}; } vector<int> solve_2(int l, int u, vector<int> w) { vector<pair<int, int>> c1, c2; for (int i = 0; i < w.size(); i++) { if (w[i] == w[0]) c1.push_back(make_pair(w[i], i)); else c2.push_back(make_pair(w[i], i)); } int cur = 0; vector<int> ans; for (int i = 0; i < c1.size(); i++) { ans.push_back(c1[i].second); cur += c1[i].first; if (l <= cur && cur <= u) return ans; } cur = 0; ans.clear(); for (int i = 0; i < c2.size(); i++) { ans.push_back(c2[i].second); cur += c2[i].first; if (l <= cur && cur <= u) return ans; } for (int i = 0; i < c1.size(); i++) for (int j = 0; j < c2.size(); j++) { vector<int> ans; int sum = 0; for (int k = 0; k <= i; k++) ans.push_back(c1[k].second), sum += c1[k].first; for (int k = 0; k <= j; k++) ans.push_back(c2[k].second), sum += c2[k].first; if (l <= sum && sum <= u) return ans; } return {}; } vector<int> solve_3(int l, int u, vector<int> w) { int n = w.size(); vector<vector<int>> dp(w.size() + 10, vector<int>(u + 10, 0)); for (int i = 0; i <= n; i++) dp[i][0] = 1; for (int i = 1; i <= n; i++) for (int j = 1; j <= u; j++) { dp[i][j] = dp[i - 1][j]; if (j - w[i - 1] >= 0) dp[i][j] |= dp[i - 1][j - w[i - 1]]; } for (int i = l; i <= u; i++) if (dp[n][i] == 1) { vector<int> ans; int sum = i, idx = n; while (sum > 0) { if (dp[idx - 1][sum - w[idx - 1]] == 1) ans.push_back(idx - 1), sum -= w[idx - 1]; idx--; } return ans; } return {}; } vector<int> find_subset(int l, int u, vector<int> w) { // sub1 bool sub1 = true; for (int i = 1; i < w.size(); i++) if (w[i] != w[i - 1]) sub1 = false; if (sub1 == true) return solve_1(l, u, w); // sub2 int mn = oo, mx = 0; for (int i = 0; i < w.size(); i++) { mn = min(mn, w[i]); mx = max(mx, w[i]); } if (mx - mn <= 1) return solve_2(l, u, w); // sub3 bool sub3 = (w.size() <= 100 && u <= 1000); for (int i = 0; i < w.size(); i++) if (w[i] > 1000) sub3 = false; if (sub3 == true) return solve_3(l, u, w); // sub4 }

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

molecules.cpp: In function 'std::vector<int> solve_1(int, int, std::vector<int>)':
molecules.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for (int i = 0; i < w.size(); i++)
      |                  ~~^~~~~~~~~~
molecules.cpp: In function 'std::vector<int> solve_2(int, int, std::vector<int>)':
molecules.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (int i = 0; i < w.size(); i++)
      |                  ~~^~~~~~~~~~
molecules.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0; i < c1.size(); i++)
      |                  ~~^~~~~~~~~~~
molecules.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < c2.size(); i++)
      |                  ~~^~~~~~~~~~~
molecules.cpp:60:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for (int i = 0; i < c1.size(); i++)
      |                  ~~^~~~~~~~~~~
molecules.cpp:61:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for (int j = 0; j < c2.size(); j++)
      |                   ~~^~~~~~~~~~~
molecules.cpp: In function 'std::vector<int> find_subset(int, int, std::vector<int>)':
molecules.cpp:107:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  107 |  for (int i = 1; i < w.size(); i++)
      |                  ~~^~~~~~~~~~
molecules.cpp:114:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |  for (int i = 0; i < w.size(); i++)
      |                  ~~^~~~~~~~~~
molecules.cpp:123:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |  for (int i = 0; i < w.size(); i++)
      |                  ~~^~~~~~~~~~
molecules.cpp:129:1: warning: control reaches end of non-void function [-Wreturn-type]
  129 | }
      | ^
#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...