Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long int
- bool solve(const vector<int>& arr) {
- unordered_map<int, int> sum_counts;
- sum_counts[0] = 1;
- for (int num : arr) {
- unordered_map<int, int> current_sums = sum_counts;
- for (auto [sum, count] : current_sums) {
- int new_sum = sum + num;
- sum_counts[new_sum]++;
- if (sum_counts[new_sum] > 1) {
- return true;
- }
- }
- }
- return false;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int n;
- cin >> n;
- if(n > 18) {
- cout << "S\n";
- return 0;
- }
- vector<int> arr(n);
- for (int i = 0; i < n; i++) cin >> arr[i];
- if (solve(arr)) {
- cout << "S\n";
- } else {
- cout << "N\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement