제출 #1296393

#제출 시각아이디문제언어결과실행 시간메모리
1296393temurbek1371Stove (JOI18_stove)C++20
100 / 100
14 ms2004 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_multiset = tree< T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define int long long #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vb vector<bool> #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define endl '\n' #define maxx(x) *max_element(all(x)) #define pii pair<int,int> #define minn(x) *min_element(all(x)) #define vpii vector<pii> #define di deque<int> #define mii map<int,int> #define vap(x) vector<array<int,x>> constexpr int MOD = 1000000007; constexpr int inf = 1e18; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); } ostream& operator<<(ostream& out, vi& a) { for (int i = 0; a.size() > i; i++)out << a[i] << ' '; return out; } ostream& operator<<(ostream& out, vector<vi>& a) { for (auto& row : a) { for (auto& elem : row) out << elem << ' '; out << '\n'; } return out; } istream& operator>>(istream& in, vi& a) { for (int i = 0; a.size() > i; i++) in >> a[i]; return in; } istream& operator>>(istream& in, vector<vi>& a) { for(int i = 0;i<a.size();i++){ for(int j = 0;j<a[i].size();j++){ in >> a[i][j]; } } return in; } int sumofvecor(vi a){ int sm = 0; for(int i = 0;i<a.size();i++)sm+=a[i]; return sm; } void file_io() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } pii getmax(vi a){ int n = a.size(); int mx = -inf,ans = 0; for(int i = 0;i<n;i++){ if(mx<a[i]){ ans = i; mx = a[i]; } } return {mx,ans}; } bool isprime(int x){ for(int i = 2;i*i<=x;i++){ if(x%i==0)return false; } return x>=2; } int binpow(int base,int power){ int res = 1; while(power>0){ if(power&1)res=(res*base)%MOD; base = (base*base)%MOD; power>>=1; } return res; } void solve(); signed main(signed argc, char *argv[]) { clock_t start = clock(); fast_io(); // file_io(); if (argc > 1 && string(argv[1]) == "gg") file_io(); int test = 1; // cin >> test; while (test--) { solve(); } cerr << "Vaqt " << double(clock() - start) / double(CLOCKS_PER_SEC) * 1000 << " ms\n"; } void solve(){ int n,k; cin>>n>>k; vi a(n); cin>>a; k--; int ans = a[n-1]-a[0]+1; vi diff(n-1); for(int i = 0;i<n-1;i++){ diff[i]=a[i+1]-a[i]-1; } sort(allr(diff)); for(int i = 0;i<k;i++){ ans-=diff[i]; } cout<<ans<<endl; }

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

stove.cpp: In function 'void file_io()':
stove.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...