結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
dgd1724
|
| 提出日時 | 2016-10-04 20:00:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,998 bytes |
| コンパイル時間 | 1,168 ms |
| コンパイル使用メモリ | 105,944 KB |
| 実行使用メモリ | 9,892 KB |
| 最終ジャッジ日時 | 2024-11-21 16:38:50 |
| 合計ジャッジ時間 | 7,983 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 3 TLE * 1 |
ソースコード
#include <iostream> //std::cout, std::cin
#include <string> //std::string,std::to_string(C++11)
#include <vector> //std::vector
#include <valarray> //std::valarray
#include <algorithm> //std::sort
#include <ctime> //localtime_s
#include <cstdlib> //abs
#include <cmath> //abs,std::pow,sqrt,sin,cos,round,floor,ceil
#include <fstream> //std::ifstream,std::ofstream
#include <iomanip> //std::setprecision,std::setw,std::setfill
#include <random> //std::random(C++11)
#include <numeric> //std::accumulate
#include <functional> //std::greater
#include <chrono> //std::chrono(C++11)
#include <bitset> //std::bitset
#include <queue> //std::queue
const static double de_PI = 3.14159265358979323846;
const static unsigned int de_MOD = 1000000007;
const static int de_MAX = 999999999;
void Calc(bool *flg, const int digit, const int compare, std::vector<int> &W, int total, const int st) {
for (unsigned int i = st; !*flg && i < W.size(); i++) {
total += W[i];
if (total > compare) {
break;
}
if (digit > 1) {
Calc(flg, digit - 1, compare, W, total, st + 1);
}
if (total == compare) {
*flg = true;
}
}
}
int main(void) {
//std::ifstream in("123.txt"); std::cin.rdbuf(in.rdbuf());
//std::ofstream ofs("456.csv");
//std::chrono::system_clock::time_point t_st = std::chrono::system_clock::now();
int N = 0, sum = 0;
std::cin >> N;
std::vector<int> W(N);
for (int i = 0; i < N; i++) {
std::cin >> W[i];
sum += W[i];
}
if (sum % 2 == 1) {
std::cout << "impossible" << std::endl;
return 0;
}
std::sort(W.begin(), W.end());
bool flg = false;
for (int i = 1; i <= N / 2; i++) {
Calc(&flg, i, sum / 2, W, 0, 0);
}
if (flg) {
std::cout << "possible" << std::endl;
}
else {
std::cout << "impossible" << std::endl;
}
//std::chrono::system_clock::time_point t_ed = std::chrono::system_clock::now();
//std::cout << std::chrono::duration_cast<std::chrono::milliseconds>(t_ed - t_st).count() << "ms" << std::endl;
}
dgd1724