結果

問題 No.833 かっこいい電車
ユーザー kamomekamome
提出日時 2022-07-26 21:55:35
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 791 ms / 2,000 ms
コード長 2,286 bytes
コンパイル時間 1,491 ms
コンパイル使用メモリ 30,604 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-23 12:19:23
合計ジャッジ時間 7,814 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 0 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 0 ms
4,376 KB
testcase_10 AC 346 ms
4,376 KB
testcase_11 AC 791 ms
4,376 KB
testcase_12 AC 67 ms
4,376 KB
testcase_13 AC 31 ms
4,380 KB
testcase_14 AC 562 ms
4,376 KB
testcase_15 AC 116 ms
4,380 KB
testcase_16 AC 68 ms
4,376 KB
testcase_17 AC 26 ms
4,380 KB
testcase_18 AC 451 ms
4,376 KB
testcase_19 AC 67 ms
4,376 KB
testcase_20 AC 5 ms
4,376 KB
testcase_21 AC 198 ms
4,376 KB
testcase_22 AC 253 ms
4,380 KB
testcase_23 AC 99 ms
4,376 KB
testcase_24 AC 255 ms
4,376 KB
testcase_25 AC 372 ms
4,380 KB
testcase_26 AC 106 ms
4,380 KB
testcase_27 AC 263 ms
4,380 KB
testcase_28 AC 101 ms
4,376 KB
testcase_29 AC 170 ms
4,380 KB
testcase_30 AC 25 ms
4,380 KB
testcase_31 AC 25 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
int N,Q;
long int x;
int q;
struct train
{
    long long int cool;
    long long int setpoint;
    int connected;
    int alias;
};


int main(){
    int modified=1;
    scanf("%d %d",&N,&Q);
    struct train t[N];
    for(int i =0;i<N;i++){
        scanf("%lld",&t[i].cool);
        t[i].setpoint=t[i].cool;
        t[i].connected=0;
        t[i].alias=-1;
    }
    for(int i =0;i<Q;i++){
        scanf("%d %ld",&q,&x);
        if(q==1){
            modified = 1;
            t[x-1].connected=1;
            //t[x].setpoint = t[x-1].setpoint+t[x].cool;
            for(int j=x-1;j<N;j++){
                if(t[j].connected == 1){
                    t[j+1].setpoint = t[j].setpoint+t[j+1].cool;
                }
                else{
                    break;
                }
            }
        }
        else if(q==2){
            modified = 1;
            //t[x].setpoint = t[x-1].setpoint-t[x].cool;
            for(int j=x-1;j<N;j++){
                if(t[j].connected == 1){
                    t[j+1].setpoint = t[j+1].setpoint-t[x-1].setpoint;
                }
                else{
                    break;
                }
            }
            t[x-1].connected=0;
            for(int j=0;j<=x;j++){t[j].alias=-1;}
        }
        else if(q==3){
            modified = 1;
            t[x-1].cool=t[x-1].cool + 1;
            t[x-1].setpoint=t[x-1].setpoint + 1;
            for(int j=x-1;j<N;j++){
                if(t[j].connected == 1){
                    t[j+1].setpoint = t[j+1].setpoint + 1;
                }
                else{
                    break;
                }
            }
        }
        else if(q==4){
            long long int res=0;
            if (t[x-1].alias==-1){modified=1;}
            if (modified==1){
                int j;
                for(j=x-1;j<N;j++){
                    if (t[j].connected ==0){
                        res=t[j].setpoint;
                        break;
                    }
                }
                for(int k=x-1;k-1<j;k++){
                    t[k].alias=j;
                }
                modified = 0;
            }
            else{
                res=t[t[x-1].alias].setpoint;
            }
            printf("%lld\n",res);
        }
    }
    return 0;
}
0