結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2019-04-18 15:02:21 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,699 bytes |
コンパイル時間 | 642 ms |
コンパイル使用メモリ | 88,380 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 09:14:33 |
合計ジャッジ時間 | 1,505 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include<iostream> #include<cmath> #include<vector> #include<set> #include<algorithm> #include<tuple> #include<utility> #include<cctype> #include<climits> #include<map> #include<queue> #include<functional> #include<stack> #include<iomanip> #include<sstream> #include<bitset> using namespace std; #define REP(i,a,n) for(int i=a;i<n;++i) #define REPL(i,a,n) for(ll i=a;i<n;++i) #define RUP(a,b) ((a+b-1)/(b)) #define ENT "\n" #define SORTVG(v) sort(v.begin(),v.end(),greater<>()) #define SORTV(v) sort(v.begin(),v.end()) #define ALL(v) (v).begin(),(v).end() #define MOD 1000000007 #define INF LLONG_MAX/2 typedef long long ll; typedef tuple<int,int,bool> Tb; typedef pair<int,int> Pii; typedef vector<int> Vi; template<class T> void chmax(T& a, T b) {if(a < b){a=b;}} template<class T> void chmin(T& a, T b) {if(a > b){a=b;}} template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}} template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}} int atcoder(){ int n,sum=0; cin>>n; Vi w(n); REP(i,0,n){ cin>>w[i]; sum+=w[i]; } if(sum&1){cout<<"impossible"<<ENT;return 0;} else sum /= 2; bool dp[n][sum+1]; REP(i,0,n) REP(j,0,sum+1) dp[i][j]=false; dp[0][0]=true; dp[0][w[0]]=true; REP(i,0,n-1){ REP(j,0,sum+1){ if(dp[i][j]){ dp[i+1][j]=true; if(j+w[i+1]<=sum) dp[i+1][j+w[i+1]]=true; } } } if(dp[n-1][sum]) cout<<"possible"<<ENT; else cout<<"impossible"<<ENT; return 0; } signed main() { cin.tie(0); ios::sync_with_stdio(false); atcoder(); return 0; }