답안 #315363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315363 2020-10-22T15:59:43 Z Pulgster Stove (JOI18_stove) C++17
100 / 100
24 ms 1664 KB
#include<bits/stdc++.h>
#include <cassert>
#include<stdarg.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
#ifdef LOCAL
		~debug() { cerr << endl; }
		eni(!=) cerr << boolalpha << i; ris; }
		eni(==) ris << range(begin(i), end(i)); }
		sim, class b dor(pair < b, c > d) {
			ris << "(" << d.first << ", " << d.second << ")";
		}
		sim dor(rge<c> d) {
			*this << "[";
			for (auto it = d.b; it != d.e; ++it)
				*this << ", " + 2 * (it == d.b) << *it;
			ris << "]";
		}
#else
		sim dor(const c&) { ris; }
#endif
	};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define pb push_back

	void read(vector<ll> &a){
		for(ll &i : a) cin >> i;
	}
void read(vector<int> &a){
	for(int &i : a) cin >> i;
}
ll mod = 1e9 + 7;
int INF = 1e9;
long long binpow(long long a, long long b) {
	a %= mod;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int gcd(int a, int b){
	return __gcd(a, b);
}
unordered_map<int, int> bad;
int calc(int n){
	if(n == 1){
		return 0;
	}
	int res = 0;
	if(n % 2 == 0){
		int w = bad[2] == 1 ? -1 : 1;
		while(n % 2 == 0){
			res += w;
			n /= 2;
		}
	}
	for(int i = 3; i * i <= n+2; i+=2){
		if(n%2 == 0){
			int w = bad[i] == 1 ? -1 : 1;
			while(n % i == 0){
				res += w;
				n /= i;
			}
		}
	}
	if(n >= 2){
		res += bad[n];
	}
	return res;
}
void test_case(int tnum){
	int n, k; 
	cin >> n >> k;
	vector<int> a(n);
	vector<int> b(n);
	read(a);
	sort(a.begin(), a.end());
	for(int i = 0; i < n-1; i++){
		b[i] = a[i+1] - a[i]-1;
		debug() << imie(a[i]) imie(a[i+1]);
	}
	int save = 0;
	sort(b.begin(), b.end(), greater<int>());
	int total = a[n-1] - a[0] + 1;
	debug() << imie(b);

	for(int i = 0; i < k-1; i++){
		total -= b[i];
		// debug() << imie(b[i]);
	}
	cout << total << '\n';

} 

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0);
	int t;
	t = 1;
	// cin >> t;
	
	while(t--){
		test_case(t);
	}
	

}

Compilation message

stove.cpp: In function 'void test_case(int)':
stove.cpp:98:6: warning: unused variable 'save' [-Wunused-variable]
   98 |  int save = 0;
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 288 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 23 ms 1624 KB Output is correct
17 Correct 24 ms 1664 KB Output is correct
18 Correct 22 ms 1664 KB Output is correct
19 Correct 22 ms 1536 KB Output is correct
20 Correct 22 ms 1664 KB Output is correct
21 Correct 22 ms 1408 KB Output is correct
22 Correct 22 ms 1536 KB Output is correct
23 Correct 22 ms 1536 KB Output is correct
24 Correct 23 ms 1408 KB Output is correct