ural 2065. Different Sums
2065. Different Sums
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Alex is a very serious mathematician and he likes to solve serious problems. For example, this problem.
You are to construct an array of n integers in which the amount of different integers is not less than k. Among all such arrays you have to construct the one with the minimal amount of different sums on non-empty subarrays. In other words, lets compute the sums of every non-empty subarray and remove repeating sums. You have to minimize the number of remaining sums.
Input
In the only line of input there are two integers n, k (1 ≤ k ≤ n ≤ 500), separated by a space.
Output
Print n integers separated by spaces — the answer for the problem. All the numbers must not be greater than 106 by absolute value. It is guaranteed that there exists an optimal solution with numbers up to 105 by absolute value. If there are multiple possible answers, you may print any of them.
Samples
input | output |
---|---|
1 1 |
-987654 |
3 2 |
0 7 0 |
Notes
Let’s take a closer look on the second sample. We will denote the sum on the segment [l,r] bysum(l,r) (elements are numbered starting with 1). sum(1, 1) = sum(3, 3) = 0, sum(1, 2) = sum(1, 3) =sum(2, 2) = sum(2, 3) = 7, so there are only two different sums.
Problem Author: Nikita Sivukhin (prepared by Alexey Danilyuk, Nikita Sivukhin)
Problem Source: Ural Regional School Programming Contest 2015
Problem Source: Ural Regional School Programming Contest 2015
Tags: none
Difficulty: 195
题意:构造一个数列,使得它们的区间和的种类最少,其中数列中不同的数的数目不少于k
分析:
首先0对于答案无影响。
那么最少的就是类似这样的数列
...........3 -2 1 -1 2 -3......
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define MIT (2147483647) 21 #define INF (1000000001) 22 #define MLL (1000000000000000001LL) 23 #define sz(x) ((int) (x).size()) 24 #define clr(x, y) memset(x, y, sizeof(x)) 25 #define puf push_front 26 #define pub push_back 27 #define pof pop_front 28 #define pob pop_back 29 #define mk make_pair 30 31 inline int getInt() 32 { 33 int ret = 0; 34 char ch = ' '; 35 bool flag = 0; 36 while(!(ch >= '0' && ch <= '9')) 37 { 38 if(ch == '-') flag ^= 1; 39 ch = getchar(); 40 } 41 while(ch >= '0' && ch <= '9') 42 { 43 ret = ret * 10 + ch - '0'; 44 ch = getchar(); 45 } 46 return flag ? -ret : ret; 47 } 48 49 int n, k; 50 deque<int> ans; 51 52 inline void input() 53 { 54 cin >> n >> k; 55 k--; 56 } 57 58 inline void solve() 59 { 60 for(int i = 1; 2 * i <= k; i++) 61 if(i & 1) ans.puf(-i), ans.pub(i); 62 else ans.puf(i), ans.pub(-i); 63 if(k & 1) ans.pub((((k / 2) & 1) ? -1 : 1) * (k / 2 + 1)); 64 for(int i = k / 2 + 1; i <= n; i++) 65 ans.pub(0); 66 for(int i = 0; i < n - 1; i++) cout << ans[i] << ' '; 67 cout << ans[n - 1] << "\n"; 68 } 69 70 int main() 71 { 72 ios::sync_with_stdio(0); 73 input(); 74 solve(); 75 return 0; 76 }