답안 #255373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255373 2020-07-31T20:38:51 Z ScarletS Lollipop (POI11_liz) C++17
100 / 100
438 ms 38672 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,m,o=0,e=0,c=0,l,r;
    pii odd;
    pii even;
    cin>>n>>m;
    string s;
    cin>>s;
    for (int i=0;i<n;++i)
    {
        if (s[i]=='T')
            c+=2;
        else
            c+=1;
        if (c&1)
        {
            if (c>o)
            {
                odd={0,i};
                o=c;
            }
        }
        else if (c>e)
        {
            even={0,i};
            e=c;
        }
    }
    c=0;
    for (int i=n-1;i+1;--i)
    {
        if (s[i]=='T')
            c+=2;
        else
            c+=1;
        if (c&1)
        {
            if (c>o)
            {
                odd={i,n-1};
                o=c;
            }
        }
        else if (c>e)
        {
            even={i,n-1};
            e=c;
        }
    }
    int dp[2*n+1][2];
    l=odd.first;r=odd.second;
    for (int i=o;i>0;i-=2)
    {
        dp[i][0]=l+1;
        dp[i][1]=r+1;
        if (s[l]=='T')
            ++l;
        else if (s[r]=='T')
            --r;
        else
        {
            ++l;
            --r;
        }
    }
    l=even.first;r=even.second;
    for (int i=e;i>0;i-=2)
    {
        dp[i][0]=l+1;
        dp[i][1]=r+1;
        if (s[l]=='T')
            ++l;
        else if (s[r]=='T')
            --r;
        else
        {
            ++l;
            --r;
        }
    }
    while (m--)
    {
        cin>>c;
        if ((c&1&&c<=o)||(!(c&1)&&c<=e))
            cout<<dp[c][0]<<" "<<dp[c][1]<<"\n";
        else 
            cout<<"NIE\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 640 KB Output is correct
3 Correct 4 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1024 KB Output is correct
2 Correct 7 ms 1024 KB Output is correct
3 Correct 29 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 2688 KB Output is correct
2 Correct 115 ms 8184 KB Output is correct
3 Correct 57 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 2808 KB Output is correct
2 Correct 24 ms 2560 KB Output is correct
3 Correct 59 ms 5112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 7544 KB Output is correct
2 Correct 81 ms 6648 KB Output is correct
3 Correct 117 ms 10116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 217 ms 17548 KB Output is correct
2 Correct 223 ms 16652 KB Output is correct
3 Correct 224 ms 20620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 18700 KB Output is correct
2 Correct 258 ms 21148 KB Output is correct
3 Correct 247 ms 25104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 438 ms 37664 KB Output is correct
2 Correct 363 ms 32788 KB Output is correct
3 Correct 305 ms 33684 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 405 ms 38076 KB Output is correct
2 Correct 405 ms 35984 KB Output is correct
3 Correct 313 ms 38672 KB Output is correct