A
Simple questions
B
Simple questions
C
Simple questions
D
Simple expectations
E
The minimum sum (|a[i]|) causes a new sequence of the sum of each successive K a[i] to be monotonically increasing
Apparently A[i]<a[i+k]<a[i+2*k]<a[i+3*k]
Find a continuous? And left end and right end greedy can
#include <cstdio> #include <cstring> #include <cstdlib>typedef __int64 ll;int a[100010], b[100010], c[ 100010];int N, m;bool cal (int s, int e, int k) {if (S < 1 && e > N) {int x = (e-k)/m;int y =-x/2;for (int i = k) ; I <= N; i + = m) a[i] = y++;} else if (S >= 1 && e > N) {int x = (e-s)/m-1;int y =-x/2;if (A[s] >=-x/2) y = a[s]+1;for (int i = s+m; I < ; = N; i + = m) a[i] = y++;} else if (S < 1 && e <= n) {int x = (e-k)/m;int y = x/2;if (a[e] <= x/2) y = a[e]-1;for (int i = e-m; I >= K ; I-= m) {A[i] = y--;}} Else{int x = (e-s)/m-1; ll tmp = (ll) a[e]-(LL) a[s]-1;if (TMP < x) return false;int y1 =-x/2;int y2 = x/2;if (A[s] >=-x/2) {y1 = a[s]+1;for (int i = s+m; I < E; i + = m) a[i] = y1++;} else if (A[e] <= x/2) {y1 = a[e]-1;for (int i = e-m; i > S; i-= m) a[i] = y1--;} else{for (int i = s+m; i < e; i + = m) a[i] = y1++;}} return true;} int main () {scanf ("%d%d", &n, &m), for (int i = 1; I <= n; i++) {char s[22];scanf ("%s", s); if (S[0] = = '? ') B[i] = 1;elsea[i] = atoi (s);} int flag = 0;for (int i = 1; I <= m; i++) {int t = 0;for (int j = i; J <= N; j + = m) {if (!b[j]) T = j;while (j <= N &am p;& B[j]) J + = M;if (T < j) {if (!cal (t, J, i)) {flag = 1;break;}} if (j <= N) t = j;} for (int j = i+m; J <= N; j + = m) {if (A[j] <= a[j-m]) {flag = 1;break;}} if (flag) break;} if (!flag) {for (int i = 1; I <= n; i++) printf ("%d", A[i]);p UTS (""); elseprintf ("Incorrect sequence\n"); return 0;}
Codeforces Round #293 (Div. 2)