#include <iostream> #include <vector> #include <cstdlib> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) #define FOR(i,a,b) for(int i=(a); i<=(b); i++) int n; int a[350]; const int INF = 2000000000; bool correct(vector<int> partial) { int m = partial.size(); FOR(i,1,m-1) partial[i] += partial[i-1]; int sum; FOR(l,1,m) { for(int offset=0; offset+l <= m; offset++) { sum = partial[offset + l - 1]; if(offset > 0) sum -= partial[offset-1]; if(sum > a[l-1]) return false; } } return true; } void solve() { vector<int> result; vector<int> partial; bool cannotBuild = false; result.push_back(a[0]); partial.push_back(a[0]); FOR(i,1,n-1) { result.push_back(-INF); int next = a[i] - a[i-1]; partial.push_back(next); if(!correct(partial)) { cannotBuild = true; break; } result.insert(result.end(), partial.begin(), partial.end()); } if(cannotBuild) { cout << "NIE" << endl; } else { cout << "TAK" << endl; cout << result.size() << endl; for(int val : result) { cout << val << " "; } } cout << endl; } int main() { cin >> n; REP(i,n) cin >> a[i]; solve(); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | #include <iostream> #include <vector> #include <cstdlib> using namespace std; #define REP(i,n) for(int i=0; i<(n); i++) #define FOR(i,a,b) for(int i=(a); i<=(b); i++) int n; int a[350]; const int INF = 2000000000; bool correct(vector<int> partial) { int m = partial.size(); FOR(i,1,m-1) partial[i] += partial[i-1]; int sum; FOR(l,1,m) { for(int offset=0; offset+l <= m; offset++) { sum = partial[offset + l - 1]; if(offset > 0) sum -= partial[offset-1]; if(sum > a[l-1]) return false; } } return true; } void solve() { vector<int> result; vector<int> partial; bool cannotBuild = false; result.push_back(a[0]); partial.push_back(a[0]); FOR(i,1,n-1) { result.push_back(-INF); int next = a[i] - a[i-1]; partial.push_back(next); if(!correct(partial)) { cannotBuild = true; break; } result.insert(result.end(), partial.begin(), partial.end()); } if(cannotBuild) { cout << "NIE" << endl; } else { cout << "TAK" << endl; cout << result.size() << endl; for(int val : result) { cout << val << " "; } } cout << endl; } int main() { cin >> n; REP(i,n) cin >> a[i]; solve(); return 0; } |