제출 #1125841

#제출 시각아이디문제언어결과실행 시간메모리
1125841InvMODBali Sculptures (APIO15_sculpture)C++20
100 / 100
57 ms1864 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define gcd __gcd #define sz(v) (int) v.size() #define pb push_back #define pi pair<int,int> #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define dbg(x) "[" #x " = " << (x) << "]" ///#define int long long using ll = long long; using ld = long double; using ull = unsigned long long; template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;} template<typename T> bool ckmn(T& a, const T& b){if(a > b) return a = b, true; return false;} const int N = 2e3+5; const ll MOD = 1e9+7; const ll INF = 1e18; int n, A, B, a[N]; namespace Subtask2{ bool checkSubtask(){ return n <= 50 && B <= min(20, n) && *max_element(a + 1, a + 1 + n) <= 10; } const int N = 55, Mx = 1005; int dp[N][Mx][25]; // dp[i][j][k]: xet den vi tri i, sumOr = j, so doan chia = k void process() { dp[0][0][0] = true; FOR(i, 1, n){ for(int k = 1; k <= B; k++){ int sum = 0; for(int x = i; x >= 1; x--){ sum += a[x]; for(int sumOr = 0; sumOr < Mx; sumOr++){ if(dp[x - 1][sumOr][k - 1]){ dp[i][sumOr | sum][k] = true; } } } } } int answer = INT_MAX; FOR(j, 0, Mx - 1){ FOR(k, A, B){ if(dp[n][j][k]){ ckmn(answer, j); } } } cout << answer <<"\n"; return; } } namespace Subtask3{ bool checkSubtask(){ return n <= 100 && A == 1 && *max_element(a + 1, a + 1 + n) <= 20; } const int N = 105, Mx = 2 * 20 * 100 + 5; int dp[N][Mx]; // dp[i][j]: so doan can chia nho nhat khi xet toi i, sumOr = j void process() { FOR(i, 0, n){ FOR(j, 0, Mx - 1){ dp[i][j] = 1e9; } } dp[0][0] = 0; FOR(i, 1, n){ int sum = 0; for(int x = i; x >= 1; x--){ sum += a[x]; FOR(j, 0, Mx - 1){ if((j | sum) < Mx){ ckmn(dp[i][j | sum], dp[x-1][j] + 1); } } } } int answer = INT_MAX; FOR(j, 0, Mx - 1){ if(dp[n][j] <= B){ ckmn(answer, j); } } cout << answer <<"\n"; return; } } namespace Subtask4{ bool checkSubtask(){ return n <= 100; } bool checkMask(ll ckMask){ vector<vector<bool>> dp(n+1, vector<bool>(B+1, false)); // dp[i][j]: xet den i, chia dc j nhom, true false giu duoc ckMask hay ko // dpt: O (n ^ 3) dp[0][0] = true; FOR(i, 1, n){ FOR(j, 1, B){ ll sum = 0; for(int x = i; x >= 1; x--){ sum += 1ll * a[x]; if((sum | ckMask) == ckMask){ if(dp[x - 1][j - 1]){ dp[i][j] = true; break; } } } } } FOR(i, A, B) if(dp[n][i]) return true; return false; } void process() { ll answer = (1ll << 44) - 1; for(int i = 43; i >= 0; i--){ if(checkMask(answer ^ (1ll << i))){ answer = answer ^ (1ll << i); } } cout << answer <<"\n"; return; } } namespace Subtask5{ bool checkSubtask(){ return n <= 2e3 && A == 1; } bool checkMask(ll ckMask){ vector<int> dp(n+1, 1e9); // dp[i] = min group de giu duoc ckMask dp[0] = 0; FOR(i, 1, n){ ll sum = 0; for(int j = i; j >= 1; j--){ sum += a[j]; if((sum | ckMask) == ckMask){ ckmn(dp[i], dp[j-1] + 1); } } } return dp[n] <= B; } void process() { ll answer = (1ll << 44) - 1; for(int i = 43; i >= 0; i--){ if(checkMask(answer ^ (1ll << i))){ answer = answer ^ (1ll << i); } } cout << answer <<"\n"; return; } } void solve() { cin >> n >> A >> B; FOR(i, 1, n) cin >> a[i]; // Subtask 1 brute force = bitmask if(Subtask2::checkSubtask()){ return Subtask2::process(), void(); } if(Subtask3::checkSubtask()){ return Subtask3::process(), void(); } if(Subtask4::checkSubtask()){ return Subtask4::process(), void(); } if(Subtask5::checkSubtask()){ return Subtask5::process(), void(); } return; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP","r",stdin); freopen(name".OUT","w",stdout); } int t = 1; //cin >> t; while(t--) solve(); return 0; }

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:235:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  235 |         freopen(name".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:236:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  236 |         freopen(name".OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...