Baekjoon #2015

Baekjoon #2015

2개의 풀이 · C++, Python

문제 원문 보기 ↗

SOLUTION INFO

C++ · main.cpp

main.cpp
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

unordered_map<ll, ll> mp;
ll prefix[200002];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll N, K; cin >> N >> K;
    ll answer = 0;
    for(int i=1;i<=N;i++) {
        cin >> prefix[i];
        prefix[i] += prefix[i - 1];

        if(prefix[i] == K) answer ++;

        if(mp.count(prefix[i] - K)) answer += mp[prefix[i] - K];
        mp[prefix[i]] ++;
    }
    cout << answer;

    return 0;
}

SOLUTION DESCRIPTION

풀이 설명

등록된 풀이 설명이 없습니다.