Submission #315363

#TimeUsernameProblemLanguageResultExecution timeMemory
315363PulgsterStove (JOI18_stove)C++17
100 / 100
24 ms1664 KiB
#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 (stderr)

stove.cpp: In function 'void test_case(int)':
stove.cpp:98:6: warning: unused variable 'save' [-Wunused-variable]
   98 |  int save = 0;
      |      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...