提出 #71498345


ソースコード 拡げる

#include <bits/stdc++.h>

#define LOCAL
#define re register
// #define int long long
namespace IO{
    #define isdigit(ch) (ch >= '0' && ch <= '9')
    constexpr int fix = 6, SIZE = 1 << 20;
    namespace Read{
        #ifndef LOCAL
            char buf[SIZE], *_now = buf, *_end = buf;
            inline char getchar(){ if(_now == _end){ _now = _end = buf; _end += fread(buf, 1, SIZE, stdin); if(_now == _end) return EOF; } return *(_now++); }
        #endif
        template <typename T>
        inline void read(T &w){ w = 0; short f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) w = (w << 1) + (w << 3) + (ch ^ 48), ch = getchar(); w *= f; }
        inline void read(char &c){ char tmp = getchar(); while(tmp == ' ' || tmp == '\n') tmp = getchar(); c = tmp; }
        #define check(ch) (ch == ' ' || ch == '\n')
        inline void read(char *s){ char ch = getchar(); while(check(ch) && ch != EOF) ch = getchar(); int len = 0; while(!check(ch) && ch != EOF) s[len++] = ch, ch = getchar(); s[len] = '\0'; }
        inline void read(std::string &s){ s.clear(); char ch = getchar(); while(check(ch) && ch != EOF) ch = getchar(); while(!check(ch) && ch != EOF) s.push_back(ch), ch = getchar(); }
        inline void read(double &w){
            w = 0; short f = 1; char ch = getchar();
            while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar();
            if(ch == '.'){ ch = getchar(); int len = 0; while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar(), ++len; while(len) w /= 10, --len; } w *= f;
        }
        inline void read(float &w){
            w = 0; short f = 1; char ch = getchar();
            while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar();
            if(ch == '.'){ ch = getchar(); int len = 0; while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar(), ++len; while(len) w /= 10, --len; } w *= f;
        }
        inline void read(long double &w){
            w = 0; short f = 1; char ch = getchar();
            while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar();
            if(ch == '.'){ ch = getchar(); int len = 0; while(isdigit(ch)) w = w * 10 + (ch ^ 48), ch = getchar(), ++len; while(len) w /= 10, --len; }  w *= f;
        }
        #undef check
        class qistream{ public: template <typename T> inline qistream &operator >> (T &a){ read(a); return *this; } inline qistream &operator >> (char *s){ read(s); return *this; } } cin;
    };
    namespace Write{
        #ifndef LOCAL
            char buf[SIZE], *p = buf;
            template <typename T> struct pres{ T num; int len; };
            template <typename T> inline pres <T> make_lf(T num, int len){ pres <T> ret; ret.num = num, ret.len = len; return ret; } inline void flush(){ fwrite(buf, 1, p - buf, stdout); p = buf; } inline void putchar(char ch){ if(p == buf + SIZE) flush(); *p = ch; ++p; } class Flush{ public: ~Flush(){ flush(); }; } _;
        #endif
        template <typename T> inline void write(T x){
            char st[50]; int len = 0;
            if(x < 0) putchar('-'), x = -x;
            do{ st[++len] = x % 10 + '0'; x /= 10; } while(x); while(len) putchar(st[len--]);
        } inline void write(char c){ putchar(c); } inline void write(const char *s){ int siz = strlen(s); for(int i = 0; i < siz; ++i) putchar(s[i]); } inline void write(char *s){ int siz = strlen(s); for(int i = 0; i < siz; ++i) putchar(s[i]); } inline void write(std::string &s){ int siz = s.size(); for(int i = 0; i < siz; ++i) putchar(s[i]); } inline void write(double x, int len = fix){
            double tmp = x; if(x < 0) putchar('-'), x = -x, tmp = -tmp; double y = 5 * powl(10, -len - 1); x += y, tmp += y; int lennow = 0; char st[50];
            if(x < 1) putchar('0');
            else for(; x >= 1; x /= 10) st[++lennow] = floor(x) - floor(x / 10) * 10 + '0';
            while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
        } inline void write(float x, int len = fix){
            float tmp = x; if(x < 0) putchar('-'), x = -x, tmp = -tmp; float y = 5 * powl(10, -len - 1); x += y, tmp += y; int lennow = 0; char st[50];
            if(x < 1) putchar('0');
            else for(; x >= 1; x /= 10) st[++lennow] = floor(x) - floor(x / 10) * 10 + '0';
            while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
        } inline void write(long double x, int len = fix){
            long double tmp = x; if(x < 0) putchar('-'), x = -x, tmp = -tmp; long double y = 5 * powl(10, -len - 1); x += y, tmp += y; int lennow = 0; char st[50];
            if(x < 1) putchar('0');
            else for(; x >= 1; x /= 10) st[++lennow] = floor(x) - floor(x / 10) * 10 + '0';
            while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
        }
        class qostream{
            public: template <typename T> inline qostream &operator << (T x){ write(x); return *this; } inline qostream &operator << (const char *s){ write(s); return *this; }
            #ifndef LOCAL
                template <typename T> inline qostream &operator << (const pres <T> x){ write(x.num, x.len); return *this; }
            #endif
        } cout;
    };
    using namespace Read; using namespace Write;
}; using namespace IO;

constexpr int N = 5e5 + 5;
int a[N], n;
struct Node{
    int l, r, sum, cover;
} t[N << 2];
void build(int l, int r, int k){
    t[k].l = l, t[k].r = r, t[k].cover = -1;
    if(l == r) return ;
    int mid = l + r >> 1;
    build(l, mid, k << 1);
    build(mid + 1, r, k << 1 | 1);
}
void pushdown(int k){
    if(t[k].cover != -1){
        t[k << 1].cover = t[k << 1 | 1].cover = t[k].cover;
        t[k << 1].sum = (t[k << 1].r - t[k << 1].l + 1) * t[k].cover;
        t[k << 1 | 1].sum = (t[k << 1 | 1].r - t[k << 1 | 1].l + 1) * t[k].cover;
        t[k].cover = -1;
    }
}
void modify(int l, int r, int k, int x){
    if(l <= t[k].l && t[k].r <= r){
        t[k].cover = x;
        t[k].sum = (t[k].r - t[k].l + 1) * x;
        return ;
    }
    pushdown(k);
    int mid = t[k].l + t[k].r >> 1;
    if(l <= mid) modify(l, r, k << 1, x);
    if(mid < r) modify(l, r, k << 1 | 1, x);
}
int query(int l, int r, int k){
    if(l <= t[k].l && t[k].r <= r) return t[k].sum;
    pushdown(k);
    int mid = t[k].l + t[k].r >> 1;
    int ans = 0;
    if(l <= mid) ans += query(l, r, k << 1);
    if(mid < r) ans += query(l, r, k << 1 | 1);
    return ans;
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    build(1, n, 1);
    int ans = 1;
    modify(1, a[1], 1, 1);
    for(int i = 2; i <= n; ++i){
        if(query(i, i, 1) == 0) break;
        modify(i, i + a[i] - 1, 1, 1);
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

提出情報

提出日時
問題 C - Domino
ユーザ Eiralys
言語 C++23 (GCC 15.2.0)
得点 300
コード長 7237 Byte
結果 AC
実行時間 156 ms
メモリ 21992 KiB

コンパイルエラー

./Main.cpp: In function 'void IO::Write::write(double, int)':
./Main.cpp:52:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   52 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |             ^~~~~
./Main.cpp:52:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   52 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |                                                  ^~~~~~~
./Main.cpp: In function 'void IO::Write::write(float, int)':
./Main.cpp:57:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   57 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |             ^~~~~
./Main.cpp:57:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   57 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |                                                  ^~~~~~~
./Main.cpp: In function 'void IO::Write::write(long double, int)':
./Main.cpp:62:13: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   62 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |             ^~~~~
./Main.cpp:62:50: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   62 |             while(lennow) putchar(st[lennow--]); putchar('.'); for(tmp *= 10; len; --len, tmp *= 10) putchar(floor(tmp) - floor(tmp / 10) * 10 + '0');
      |                                                  ^~~~~~~
./Main.cpp: In function 'void build(int, int, int)':
./Main.cpp:82:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   82 |     int mid = l + r >> 1;
      |               ~~^~~
./Main.cpp: In function 'void modify(int, int, int, int)':
./Main.cpp:101:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  101 |     int mid = t[k].l + t[k].r >> 1;
      |               ~~~~~~~^~~~~~~~
./Main.cpp: In function 'int query(int, int, int)':
./Main.cpp:108:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  108 |     int mid = t[k].l + t[k].r >> 1;
      |               ~~~~~~~^~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 20
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
min.txt AC 1 ms 3604 KiB
random_01.txt AC 144 ms 21908 KiB
random_02.txt AC 50 ms 12428 KiB
random_03.txt AC 140 ms 21800 KiB
random_04.txt AC 24 ms 7980 KiB
random_05.txt AC 95 ms 21900 KiB
random_06.txt AC 23 ms 21672 KiB
random_07.txt AC 47 ms 21980 KiB
random_08.txt AC 60 ms 21064 KiB
random_09.txt AC 62 ms 21992 KiB
random_10.txt AC 111 ms 21248 KiB
random_11.txt AC 156 ms 21840 KiB
random_12.txt AC 11 ms 12308 KiB
random_13.txt AC 10 ms 21852 KiB
random_14.txt AC 89 ms 21772 KiB
random_15.txt AC 89 ms 21968 KiB
random_16.txt AC 119 ms 21936 KiB
sample_01.txt AC 1 ms 3584 KiB
sample_02.txt AC 1 ms 3560 KiB
sample_03.txt AC 1 ms 3632 KiB