제출 #251302

#제출 시각아이디문제언어결과실행 시간메모리
251302jimmy123새로운 문제 (POI11_liz)C++14
100 / 100
515 ms19704 KiB
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;
const int MAX_NUM = 1000000;
char data[MAX_NUM+1];
int location[2*MAX_NUM+1]={0};


int main(){
    int num=0, query=0, cnt=1, pos=0, first_W=-1, last_W=-1, range, i, add;
    bool isfirst = true, got = false;
    scanf("%d%d%s", &num, &query, data);
    vector<int> Wpos;

    for(i=0;i<num;++i){
        if(data[i] == 'W'){
            pos += 1;
            last_W = pos;
            if(isfirst){
                first_W = pos;
                Wpos.push_back(pos);
                isfirst = false;
            }
            if(add > 1000){
                Wpos.push_back(pos);
                add = 0;
            }
        }
        else
            pos += 2;
        location[pos] = cnt;
        cnt += 1;
        add += 1;
    }
    Wpos.push_back(last_W);

    for(i=0;i<query;++i){
        if(i != 0)
            printf("\n");

        got = false;
        scanf("%d", &range);
        if(location[range] != 0){
            printf("1 %d", location[range]);
            continue;
        }

        if(first_W != -1 && first_W < range){
            if(first_W+range<=2*MAX_NUM && location[first_W+range] != 0){
                printf("%d %d", location[first_W]+1, location[first_W+range]);
                got = true;
            }
            else if(first_W+range-1<=2*MAX_NUM && location[first_W+range-1] != 0){
                printf("%d %d", location[first_W-1]+1, location[first_W+range-1]);
                got = true;
            }
        }

        int idx = upper_bound(Wpos.begin(), Wpos.end(), range) - Wpos.begin();
        //if(last_W != -1 && last_W > range){
        if(idx != Wpos.size() && !got){
            if(Wpos[idx]-range<=2*MAX_NUM && location[Wpos[idx]-range] != 0){
                printf("%d %d", location[Wpos[idx]-range]+1, location[Wpos[idx]]);
                got = true;
            }
            else if(Wpos[idx]-range-1<=2*MAX_NUM && location[Wpos[idx]-range-1] != 0){
                printf("%d %d", location[Wpos[idx]-range-1]+1, location[Wpos[idx]-1]);
                got = true;
            }
        }
        
        // 找不到解
        if(!got)
            printf("NIE");
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

liz.cpp: In function 'int main()':
liz.cpp:63:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(idx != Wpos.size() && !got){
            ~~~~^~~~~~~~~~~~~~
liz.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%s", &num, &query, data);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
liz.cpp:44:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &range);
         ~~~~~^~~~~~~~~~~~~~
liz.cpp:26:13: warning: 'add' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(add > 1000){
             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...