제출 #22562

#제출 시각아이디문제언어결과실행 시간메모리
22562카시코이 (#40)Unifying Values (KRIII5_UV)C++14
0 / 7
500 ms3408 KiB
#include <cstdio> #include <cstring> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; const int MOD = 1000000007; int n; long long arr[10004]; long long sum[10004]; long long allsum; int d[2][10004]; int main() { //freopen("input.txt", "r", stdin); scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%lld", &arr[i]); sum[i] = sum[i - 1] + arr[i]; } allsum = sum[n]; unordered_map<long long, vector<int>> posbysum; for (int i = 0; i <= n; ++i) { posbysum[sum[i]]; posbysum[sum[i]].push_back(i); } vector<int> cand; for (int i = 2; i <= n; ++i) { if (allsum % i == 0) { cand.push_back(i); } } long long ans = 0; if (allsum == 0) { long long targetsum = 0; vector<int> nxtp(n + 1); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; nxtp[j] = upper_bound(posv.begin(), posv.end(), j) - posv.begin(); } d[0][0] = 1; for (int k = 1; k <= n; ++k) { memset(d[k % 2], 0, sizeof(d[k % 2])); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; auto it = posv.begin() + nxtp[j]; while (it != posv.end()) { d[k % 2][*it] = (d[k % 2][*it] + d[1 - k % 2][j]) % MOD; ++it; } } if (k >= 2) ans += d[k % 2][n]; } printf("%d\n", ans % MOD); return 0; } for (int cnt : cand) { long long targetsum = allsum / cnt; vector<int> nxtp(n + 1); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; nxtp[j] = upper_bound(posv.begin(), posv.end(), j) - posv.begin(); } d[0][0] = 1; for (int k = 1; k <= cnt; ++k) { memset(d[k % 2], 0, sizeof(d[k % 2])); for (int j = 0; j < n; ++j) { long long sumi = sum[j] + targetsum; vector<int>& posv = posbysum[sumi]; auto it = posv.begin() + nxtp[j]; while (it != posv.end()) { d[k % 2][*it] = (d[k % 2][*it] + d[1 - k % 2][j]) % MOD; ++it; } } } ans += d[cnt % 2][n]; } printf("%d\n", ans % MOD); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

UV.cpp: In function 'int main()':
UV.cpp:66:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%d\n", ans % MOD);
                           ^
UV.cpp:97:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n", ans % MOD);
                          ^
UV.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
UV.cpp:21:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &arr[i]);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...