#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define FOR(i,n) for(int i=0;i<n;++i)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define inp1(a) scanf("%d",&a)
#define inp2(a,b) scanf("%d%d",&a,&b)
#define inp3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inp4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)
#define inp5(a,b,c,d,e) scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)
#define fastio() ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vector<int> > vvi;
typedef pair<int,pair<int,int> > piii;
typedef vector<piii> viii;
const double EPSILON = 1e-9;
const double PI = acos(-1);
const int MOD = 1e9+7;
const int INF = 0x3c3c3c3c;
const long long INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 102;
ll pSum[10003];
ll A[10003];
int N;
unordered_map<ll,int> mp;
ll go(int pos, int cnt){
if(pos>N) return cnt==0;
auto it = mp.find(pos*10001+cnt);
if(it != mp.end()) return (*it).second;
ll ans = 0;
for(int i = pos; i <= N; i++){
if(pSum[N]==0 && pSum[i]-pSum[pos-1] != 0) continue;
if(pos==1) {
if(i==N) continue;
if(pSum[i] && pSum[N]%pSum[i]) continue;
ans = (ans + go(i+1, pSum[i]?pSum[N]/pSum[i]-1:0)) % MOD;
}
else {
if(pSum[N]-pSum[pos-1] != (pSum[i]-pSum[pos-1])*cnt) continue;
ans = (ans + go(i+1, pSum[N]?cnt-1:0)) % MOD;
}
}
return mp[pos*10001+cnt] = ans;
}
int main() {
inp1(N);
FOR(i,N) scanf("%lld",A+i), pSum[i+1] = pSum[i] + A[i];
printf("%lld", go(1,0));
return 0;
}
Compilation message
UV.cpp: In function 'int main()':
UV.cpp:56:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
inp1(N);
^
UV.cpp:57:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
FOR(i,N) scanf("%lld",A+i), pSum[i+1] = pSum[i] + A[i];
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2180 KB |
Output is correct |
2 |
Correct |
0 ms |
2180 KB |
Output is correct |
3 |
Correct |
0 ms |
2180 KB |
Output is correct |
4 |
Correct |
229 ms |
3988 KB |
Output is correct |
5 |
Correct |
226 ms |
3992 KB |
Output is correct |
6 |
Execution timed out |
500 ms |
3484 KB |
Execution timed out |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
3152 KB |
Output is correct |
2 |
Correct |
103 ms |
2784 KB |
Output is correct |
3 |
Correct |
96 ms |
2780 KB |
Output is correct |
4 |
Correct |
466 ms |
4344 KB |
Output is correct |
5 |
Correct |
373 ms |
3948 KB |
Output is correct |
6 |
Execution timed out |
500 ms |
4212 KB |
Execution timed out |
7 |
Halted |
0 ms |
0 KB |
- |