Submission #22666

#TimeUsernameProblemLanguageResultExecution timeMemory
22666카시코이 (#40)Unifying Values (KRIII5_UV)C++14
2 / 7
500 ms48756 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 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); } long long ans = 0; if (allsum == 0) { int ppcnt = 0; long long ss = 0; for (int i = 1; i <= n; ++i) { ss += arr[i]; if (ss == 0) { ++ppcnt; } } ans = 1; for (int k = 1; k < ppcnt; ++k) { ans = (ans * 2ll) % MOD; } ans = (ans - 1 + MOD) % MOD; printf("%d\n", ans); return 0; } vector<int> cand; for (int i = 2; i <= n; ++i) { if (allsum % i == 0) { cand.push_back(i); } } posbysum[0] = vector<int>{ 0 }; vector<vector<int>> sum1(n + 1), prefix(n + 1); for (int cnt : cand) { long long targetsum = allsum / cnt; sum1[0] = vector<int>{ 1 }; prefix[0] = vector<int>{ 1 }; for (int k = 1; k <= cnt; ++k) { long long ss = targetsum * k; vector<int>& curidx = posbysum[ss]; vector<int>& prvidx = posbysum[targetsum * (k - 1)]; sum1[k].resize(curidx.size(), 0); prefix[k].resize(curidx.size(), 0); int p = 0; for (int j = 0; j < curidx.size(); ++j) { while (p < prvidx.size() && prvidx[p] < curidx[j]) { ++p; } sum1[k][j] = (p == 0) ? 0 : prefix[k - 1][p - 1]; prefix[k][j] = (j == 0 ? 0 : prefix[k][j - 1]) + sum1[k][j]; prefix[k][j] %= MOD; } } ans += sum1[cnt].back(); } printf("%d\n", ans % MOD); return 0; }

Compilation message (stderr)

UV.cpp: In function 'int main()':
UV.cpp:47:21: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%d\n", ans);
                     ^
UV.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < curidx.size(); ++j) {
                      ^
UV.cpp:76:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (p < prvidx.size() && prvidx[p] < curidx[j]) {
              ^
UV.cpp:87: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:17:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
UV.cpp:19: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...