도데체 어디서 틀리는지 모르겠다...
찾을 수 있으려나
#include <iostream>
#include <vector>
#include <algorithm>
int main(void) {
std::ios_base::sync_with_stdio(false);
std::cin.tie(NULL);
int size;
std::cin >> size;
int aLen, bLen;
std::cin >> aLen >> bLen;
std::vector<int> aVal(aLen), bVal(bLen);
for (int i = 0; i < aLen; i++) {
std::cin >> aVal[i];
}
for (int i = 0; i < bLen; i++) {
std::cin >> bVal[i];
}
std::vector<int> aSum;
for (int front = 0; front < aLen; front++) {
int sum = 0;
int cur = front - 1;
do {
cur = cur++;
sum += aVal[cur % aLen];
aSum.push_back(sum);
//std::cout << sum << ", " << cur % aLen << ", " << aVal[cur % aLen] << "\n";
} while (sum + aVal[(cur + 1) % aLen] <= size && (front != 0 || (cur % aLen) != 0) && (cur % aLen) + 1 != front);
//std::cout << "check" << "\n";
}
//std::cout << "check" << "\n";
std::vector<int> bSum;
for (int front = 0; front < aLen; front++) {
int sum = 0;
int cur = front - 1;
do {
cur = cur++;
sum += bVal[cur % bLen];
bSum.push_back(sum);
//std::cout << sum << ", " << cur % bLen << ", " << bVal[cur % bLen] << "\n";
} while (sum + bVal[(cur + 1) % bLen] <= size && (front != 0 || (cur % bLen) != 0) && (cur % bLen) + 1 != front);
}
aSum.push_back(0);
bSum.push_back(0);
std::sort(aSum.begin(), aSum.end());
std::sort(bSum.begin(), bSum.end());
long long front = 0, end = bSum.size() - 1;
long long count = 0;
while (front < aSum.size() && end >= 0) {
if (aSum[front] + bSum[end] == size) {
long long aCnt = 1, bCnt = 1;
front++, end--;
//std::cout << end << ", " << bSum.size() << "\n";
while (front < aSum.size() && aSum[front] == aSum[front - 1]) {
front++;
aCnt++;
}
while (end >= 0 && bSum[end] == bSum[end + 1]) {
end--;
bCnt++;
}
count += aCnt * bCnt;
}
else if (aSum[front] + bSum[end] > size) {
//std::cout << front << ", " << aSum.size() << "\n";
end--;
}
else if (aSum[front] + bSum[end] < size) {
//std::cout << front << ", " << aSum.size() << "\n";
front++;
}
}
/*for (int i = 0; i < aSum.size(); i++) {
std::cout << aSum[i] << "\n";
}*/
std::cout << count << "\n";
return 0;
}
|
cs |
'problem solving' 카테고리의 다른 글
3108번: 로고 (0) | 2020.03.02 |
---|---|
2667번: 단지번호붙이기 (0) | 2020.03.02 |
2579번: 계단 오르기 (0) | 2020.03.01 |
2331번: 반복수열 (0) | 2020.03.01 |
2089번: -2진수 (0) | 2020.02.27 |