답안 #137630

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137630 2019-07-28T07:44:52 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 C = 0, D = 0;
		for(int j=k[i-1]+1;j<=k[i];j++) {
			if(e[j] >= I) {
				C++;
				if(s[j] < I) D++;
				e[j] -= I;
				s[j] -= min(s[j], I);
			}
		}
		if(D && (!R || C > 1)) 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:39: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:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&k[i]);
   ~~~~~^~~~~~~~~~~~
bitwise.cpp:45: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]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 348 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 376 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 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct