제출 #94971

#제출 시각아이디문제언어결과실행 시간메모리
94971psmaoStove (JOI18_stove)C++14
0 / 100
2 ms256 KiB
#include <bits/stdc++.h>
using namespace std;

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
#define fd(i,s,t) for(int i = s; i >= t; -- i)
#define bf(i,s) for(int i = head[s]; i; i = e[i].next)
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
#define VI vector<int>
#define sf scanf
#define pf printf
#define fp freopen
#define SZ(x) ((int)(x).size())
#ifdef MPS
#define D(x...) printf(x)
#else
#define D(x...)
#endif
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
const int inf = 1<<30;
const ll INF = 1ll<<60;
const db Inf = 1e20;
const db eps = 1e-9;

void gmax(int &a,int b){a = (a > b ? a : b);}
void gmin(int &a,int b){a = (a < b ? a : b);}

const int maxn = 100050;

int n, K, T[maxn];

bool jud(int x)
{
	int tmp = K - 1, last = 0;
	fo(i,2,n)
	{
		if(T[i] - T[last+1] + 1 > x)
		{
			last = i - 1;
			-- tmp;
			if(tmp < 0) return false;
		}
	}
	return true;
}
int calc(int x)
{
	int last = 0, ans = 0;
	fo(i,2,n)
	{
		if(T[i] - T[last+1] + 1 > x)
		{
			ans += T[i-1] - T[last+1] + 1;
			last = i-1;
		}
	}
	ans += T[n] - T[last+1] + 1;
	return ans;
}
int main()
{
	#ifdef MPS
		fp("1.in","r",stdin);
		fp("1.out","w",stdout);
	#endif
	sf("%d%d",&n,&K);
	fo(i,1,n) sf("%d",&T[i]);
	int lo = 1, hi = 1000000000, mid, pos;
	while(lo <= hi)
	{
		mid = lo + hi >> 1;
		if(jud(mid)) pos = mid, hi = mid - 1;
		else lo = mid + 1;
	}
	pf("%d\n",calc(pos));
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:76:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = lo + hi >> 1;
         ~~~^~~~
stove.cpp:71:4: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  sf("%d%d",&n,&K);
    ^
stove.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  fo(i,1,n) sf("%d",&T[i]);
              ^
stove.cpp:80:4: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  pf("%d\n",calc(pos));
    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...