結果

問題 No.1505 Zero-Product Ranges
ユーザー reddy nishanthreddy nishanth
提出日時 2021-05-14 22:12:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 21 ms / 2,000 ms
コード長 4,376 bytes
コンパイル時間 857 ms
コンパイル使用メモリ 110,416 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-10 00:31:09
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 19 ms
6,944 KB
testcase_04 AC 18 ms
6,944 KB
testcase_05 AC 9 ms
6,940 KB
testcase_06 AC 8 ms
6,944 KB
testcase_07 AC 6 ms
6,940 KB
testcase_08 AC 8 ms
6,944 KB
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 8 ms
6,940 KB
testcase_12 AC 6 ms
6,944 KB
testcase_13 AC 11 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 17 ms
6,944 KB
testcase_16 AC 21 ms
6,944 KB
testcase_17 AC 20 ms
6,940 KB
testcase_18 AC 21 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 20 ms
6,940 KB
testcase_23 AC 19 ms
6,940 KB
testcase_24 AC 19 ms
6,940 KB
testcase_25 AC 18 ms
6,944 KB
testcase_26 AC 19 ms
6,944 KB
testcase_27 AC 19 ms
6,940 KB
testcase_28 AC 19 ms
6,940 KB
testcase_29 AC 20 ms
6,944 KB
testcase_30 AC 20 ms
6,944 KB
testcase_31 AC 19 ms
6,940 KB
testcase_32 AC 11 ms
6,940 KB
testcase_33 AC 10 ms
6,944 KB
testcase_34 AC 12 ms
6,944 KB
testcase_35 AC 9 ms
6,940 KB
testcase_36 AC 9 ms
6,940 KB
testcase_37 AC 10 ms
6,940 KB
testcase_38 AC 11 ms
6,944 KB
testcase_39 AC 11 ms
6,940 KB
testcase_40 AC 11 ms
6,940 KB
testcase_41 AC 12 ms
6,944 KB
testcase_42 AC 3 ms
6,944 KB
testcase_43 AC 3 ms
6,940 KB
testcase_44 AC 3 ms
6,940 KB
testcase_45 AC 3 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 3 ms
6,940 KB
testcase_48 AC 3 ms
6,944 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 3 ms
6,944 KB
testcase_51 AC 3 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

typedef long long ll;
typedef long long unsigned int llui;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > vvi;
typedef vector< vector<ll> > vvl;
typedef set<int> si;
typedef map<string, int> msi;
typedef map<int, int> mii;

using str = string; // yay python!

#define INF 1000000000
#define MOD 1000000007
#define EPS 1e-9
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort((x).begin(),(x).end())
#define UNIQUE(x) SORT(x),(x).erase(unique((x).begin(),(x).end()),(x).end())
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define LB lower_bound
#define UB upper_bound
#define SZ(a) int((a).size())
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,b) memset(a,b,sizeof(a))
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

#define FOR(i,a,b) for (int i = int(a); i < int(b); i++)
#define FORD(i,a,b) for(int i=int(b)-1; i>=int(a); i--)
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REP1(i,n) for (int i = 1; i <= int(n); i++)
#define REV(i, n) for (int i = int(n)-1; i >=0 ; i--)

#define sd(n) scanf("%d",&n)
#define dsd(n) int n; scanf("%d",&n)
#define sd2(a,b) scanf("%d%d",&a,&b)
#define dsd2(a,b) int a,b; scanf("%d%d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define dsd3(a,b,c) int a,b,c; scanf("%d%d%d",&a,&b,&c)
#define pd(n) printf("%d\n",n)
#define pds(n) printf("%d ",n)
#define sl(n) scanf("%lld",&n)
#define dsl(n) ll n; scanf("%lld",&n)
#define sl2(a,b) scanf("%lld%lld",&a,&b)
#define dsl2(a,b) ll a,b; scanf("%lld%lld",&a,&b)
#define sl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define dsl3(a,b,c) ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c)
#define pl(n) printf("%lld\n",n)  
#define pls(n) printf("%lld ",n)  

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }

#define LSOne(S) (S&(-S))

const double pi = acos(-1);
//const int oo = 0x3f3f3f3f;

int cmp(double x, double y = 0, double tol = EPS) {
    return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

template<class T> bool uin(T &a,T b) {return a > b ? (a=b, true):false;}
template<class T> bool uax(T &a,T b) {return a < b ? (a=b, true):false;}

/////////////////////////////////////////////////////////////////////

int main(){
    dsd(n);
    vi V(n);
    vi R(n);
    REP(i,n) sd(V[i]);
    int ind = n;
    for(int i=n-1;i>=0;i--){
        R[i] = ind;
        if(V[i]==0) ind = i;
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        if(V[i]==0){
            ans+=(n-i);
            continue;
        }
        if(R[i]==n){
            continue;
        }
        ans += (n-R[i]);
    }
    pl(ans);
    return 0;
}
// Do something instead of nothing, stay organised, stay ahead!, WRITE STUFF DOWN
0