Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- #include <fstream>
- int main() {
- string data;
- ifstream file("27.txt");
- getline(file, data);
- int N = stoi(data);
- vector <int> a;
- int ans = 0;
- for (int k = 0; k < N; ++k) {
- getline(file, data);
- int x = stoi(data) % 1111;
- a.pb(x);
- if (x == 0) {
- ans++;
- }
- }
- /*int Si = 0, Sj;
- cout << "N = " << N << "\n";
- for (int i = 0; i < N; ++i) {
- Si += a[i];
- Si %= 1111;
- Sj = 0;
- for (int j = 0; j < i; ++j) {
- Sj += a[j];
- Sj %= 1111;
- if (Si == Sj) {
- cout << i << ' ' << j << "\n";
- ans++;
- }
- }
- }
- cout << ans;*/
- cout << "N = " << N << "\n";
- vector <int> pf(N);
- pf[0] = a[0];
- for (int i = 1; i < N; ++i) {
- pf[i] = pf[i - 1] + a[i];
- pf[i] %= 1111;
- }
- vector <vector <int> > cnt(1111, vector <int> (N, 0));
- for (int i = 0; i < N; ++i) {
- cnt[pf[i]][i]++;
- }
- cnt[a[0]][0]=1;
- for (int i = 1; i < N; ++i) {
- for (int j = 0; j < 1111; ++j) {
- if (j == a[i]) {
- cnt[j][i] = cnt[j][i - 1] + 1;
- } else {
- cnt[j][i] = cnt[j][i - 1];
- }
- }
- }
- //int ans = 0;
- if (pf[0] == 0) {
- ans++;
- }
- for (int i = 1; i < N; ++i) {
- int S = pf[i];
- //cout << "S = " << S << "\n";
- int d = (1111 - S) % 1111;
- ans += cnt[d][i-1];
- }
- cout << "ans\n";
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement