Submission #137628

# Submission time Handle Problem Language Result Execution time Memory
137628 2019-07-28T07:42:25 Z khsoo01 Bitwise (BOI06_bitwise) C++11
100 / 100
2 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

const int N = 105;

int n, m, k[N], s[N], e[N], ans;
bool dn[N];

bool can (int I) {
	bool R = true;
	for(int i=1;i<=m;i++) {
		if(dn[i]) continue;
		bool F = false;
		for(int j=k[i-1]+1;j<=k[i];j++) {
			if(e[j] >= I) F = true;
		}
		if(!F) {
			R = false;
			break;
		}
	}
	for(int i=1;i<=m;i++) {
		int C1 = 0, C2 = 0;
		for(int j=k[i-1]+1;j<=k[i];j++) {
			if(e[j] >= I) {
				e[j] -= I;
				if(s[j] >= I) {
					C1++;
					s[j] -= I;
				}
				else {
					C2++;
					s[j] = 0;
				}
			}
		}
		if((!R && C2) || (C1 + C2 > 1 && C2)) dn[i] = true;
	}
	return R;
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d",&k[i]);
		k[i] += k[i-1];
	}
	for(int i=1;i<=n;i++) {
		scanf("%d%d",&s[i],&e[i]);
	}
	for(int i=(1<<30);i;i/=2) {
		if(can(i)) ans += i;
	}
	printf("%d\n", ans);
}

Compilation message

bitwise.cpp: In function 'int main()':
bitwise.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
bitwise.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k[i]);
   ~~~~~^~~~~~~~~~~~
bitwise.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&s[i],&e[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct