Submission #1219469

#TimeUsernameProblemLanguageResultExecution timeMemory
1219469sleepntsheepFlooding Wall (BOI24_wall)C11
0 / 100
136 ms396 KiB
#include <stdio.h>
#define N 22 

int n, a[N], b[N], v[N], pmx[N], smx[N];
long long answer;

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) scanf("%d", a + i);
	for (int i = 0; i < n; ++i) scanf("%d", b + i);

	for (int m = 0; m < (1 << n); ++m) {
		for (int i = 0; i < n; ++i)
			v[i] = (m >> i) & 1 ? a[i] : b[i];

		pmx[1] = v[0];
		for (int i = 1; i < n - 1; ++i)
			pmx[i + 1] = pmx[i] > v[i] ? pmx[i] : v[i];
		smx[n - 2] = v[n - 1];
		for (int i = n - 2; i >= 1; --i)
			smx[i - 1] = smx[i] > v[i] ? smx[i] : v[i];
		for (int i = 1; i < n - 1; ++i) {
			int y = pmx[i] < smx[i] ? pmx[i] : smx[i];
			if (y > v[i])
				answer += y - v[i];
		}
	} 
	printf("%lld\n", answer);

	return 0;
}

Compilation message (stderr)

Main.c: In function 'main':
Main.c:8:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
Main.c:9:37: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |         for (int i = 0; i < n; ++i) scanf("%d", a + i);
      |                                     ^~~~~~~~~~~~~~~~~~
Main.c:10:37: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         for (int i = 0; i < n; ++i) scanf("%d", b + i);
      |                                     ^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...