답안 #251298

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251298 2020-07-20T17:02:52 Z jimmy123 Lollipop (POI11_liz) C++14
82 / 100
529 ms 18556 KB
#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;
    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");

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

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

    return 0;
}

Compilation message

liz.cpp: In function 'int main()':
liz.cpp:51:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(idx != Wpos.size()){
            ~~~~^~~~~~~~~~~~~~
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:43: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){
             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 7 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 640 KB Output is correct
2 Correct 11 ms 640 KB Output is correct
3 Correct 40 ms 1324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 1528 KB Output is correct
2 Correct 148 ms 4088 KB Output is correct
3 Correct 85 ms 2572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 1536 KB Output is correct
2 Correct 32 ms 1280 KB Output is correct
3 Correct 77 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 3832 KB Output is correct
2 Correct 108 ms 3320 KB Output is correct
3 Correct 147 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 249 ms 8684 KB Output is correct
2 Correct 240 ms 8056 KB Output is correct
3 Correct 272 ms 11000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 219 ms 9236 KB Output is correct
2 Correct 270 ms 9976 KB Output is correct
3 Correct 318 ms 13444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 509 ms 18556 KB Output is correct
2 Correct 387 ms 15608 KB Output is correct
3 Runtime error 17 ms 16384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Incorrect 529 ms 18512 KB Bledny przedzial
2 Halted 0 ms 0 KB -