답안 #926142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
926142 2024-02-12T15:35:03 Z Chal1k Stove (JOI18_stove) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#include <algorithm>
#include <math.h>
using namespace std;
#define  SPEED ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define str string
#define pb push_back
#define pf push_front
#define nl "\n"
#define ll long long
#define ull unsigned long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define len(a) a.size()
#define sz(v) (int)(v.size())
#define pii pair<int,int>
const int N = 2e3 + 1;
const int md = 998244353;
const int mod = 1e9 + 7;
const int mega = 1e6 + 3;
long long gcd(long long int a, long long int b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
long long lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}
void solve(){
    int n , k;
    cin >> n >> k;
    int a[n+1];
    for(int i = 1; i <= n; ++i)cin >> a[i];
    if(n == k){
        cout << n;
    }
    else{
        int sum = 0;
        if(k == 1){
            cout << a[n];
        }
        else{
            int kol = 0;
            for(int i = 1; i <= n; ++i){
                if(i + (n/k) - 1 <= n)kol += (a[i + (n/k) - 1]) - a[i] + 1,i+= n/k;
                else {kol += a[n]+1 - a[i] ; break;}
            }
            cout << kol + (n/k+1);
        }
    }
}
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    SPEED;
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:42:13: warning: unused variable 'sum' [-Wunused-variable]
   42 |         int sum = 0;
      |             ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -