Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std; const int maxn = 1005; typedef long long ll; int dp[maxn][maxn]; ll pref_sum[maxn]; ll sum(int L, int R) { return pref_sum[R] - pref_sum[L - 1]; } ll bin_search(int i, int j, ll s) { int L = i, R = j; while(L <= R) { int mid = (L + R) / 2; ll x = sum(i, mid); if(x == s and (mid == i or sum(i, mid - 1) != s)) { return mid; } else if(x >= s) { R = mid - 1; } else { L = mid + 1; } } return -1; } int rec(int i, int j) { ll s = sum(i, j); if(i < j and s % 2 == 0) { int idx = bin_search(i, j, s / 2); if(idx != -1) { return max(rec(i, idx), rec(idx + 1, j)) + 1; } } return 0; } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while(t--) { int n; cin >> n; vector
v(n); ll s = 0; for(int i =0 ; i < n; i++) { cin >> v[i]; s += v[i]; pref_sum[i] = s; } cout << rec(0, n - 1) << endl; } return 0; } /* 5 9 7 ...##.... ..#.##..# ..#....## .##...#.. ....#.... WS?EE?? **/
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)