답안 #51683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51683 2018-06-19T23:37:42 Z gs13105 영역 (JOI16_ho_t4) C++17
15 / 100
107 ms 9804 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

struct pos
{
    int x, y;
    bool operator <(const pos &p) const
    {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator ==(const pos &p) const
    {
        return x == p.x && y == p.y;
    }
};

struct eve
{
    int x, e;
    bool operator <(const eve &a) const
    {
        return x != a.x ? x < a.x : e < a.e;
    }
};

inline int irem(int x, int y)
{
    assert(y != 0);
    y = abs(y);
    return (x % y + y) % y;
}

int kx, ky;
pair<pos, int> decom(pos p)
{
    if(kx != 0)
    {
        pos q;
        q.x = irem(p.x, kx);

        int t = (q.x - p.x) / kx;
        assert(q.x == p.x + t * kx);
        q.y = p.y + t * ky;
        assert(q.y == p.y + 1LL * t * ky);
        return { q, t };
    }
    if(ky != 0)
    {
        pos q;
        q.y = irem(p.y, ky);

        int t = (q.y - p.y) / ky;
        assert(q.y == p.y + t * ky);
        q.x = p.x + t * kx;
        assert(q.x == p.x + 1LL * t * kx);
        return { q, t };
    }
    return { p, 0 };
}

vector<pos> com;
inline int idx(pos p)
{
    return lower_bound(com.begin(), com.end(), p) - com.begin();
}

char str[100010];
pos arr[100010];

pos base[100010];
int off[100010];

vector<int> lis[100010];
const int dx[4] = { 0, 0, 1, 1 };
const int dy[4] = { 0, 1, 0, 1 };

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, k, i;
    scanf("%d%d%s", &n, &k, str);

    kx = ky = 0;
    for(i = 0; i <= n; i++)
    {
        arr[i] = { kx, ky };
        if(i == n)
            break;

        if(str[i] == 'E')
            kx++;
        else if(str[i] == 'N')
            ky++;
        else if(str[i] == 'W')
            kx--;
        else
            ky--;
    }

    for(i = 0; i <= n; i++)
    {
        tie(base[i], off[i]) = decom(arr[i]);
        com.push_back(base[i]);
    }
    sort(com.begin(), com.end());
    com.erase(unique(com.begin(), com.end()), com.end());
    int sz = com.size();

    for(i = 0; i <= n; i++)
        lis[idx(base[i])].push_back(off[i]);

    for(i = 0; i < sz; i++)
        sort(lis[i].begin(), lis[i].end());

    long long res = 0;
    for(i = 0; i < sz; i++)
    {
        int a[4];
        int b[4];

        bool ok = 1;
        for(int d = 0; d < 4; d++)
        {
            pos p;
            tie(p, b[d]) = decom({ com[i].x + dx[d], com[i].y + dy[d] });
            a[d] = idx(p);
            if(!(a[d] < com.size() && com[a[d]] == p))
            {
                ok = 0;
                break;
            }
        }
        if(!ok)
            continue;

        vector<eve> v;
        for(int d = 0; d < 4; d++)
        {
            for(int l : lis[a[d]])
            {
                v.push_back({ l - b[d], d + 1 });
                v.push_back({ l - b[d] + k, -(d + 1) });
            }
        }
        sort(v.begin(), v.end());

        int s[4];
        memset(s, 0, sizeof s);

        int cnt = 0;
        bool inr = 0;
        int sta;
        for(int j = 0; j < v.size(); j++)
        {
            eve t = v[j];
            if(t.e > 0)
            {
                t.e--;
                s[t.e]++;
                if(s[t.e] == 1)
                    cnt++;
            }
            else
            {
                t.e = -t.e - 1;
                s[t.e]--;
                if(s[t.e] == 0)
                    cnt--;
            }

            if(j == (int)v.size() - 1 || t.x != v[j + 1].x)
            {
                if(!inr && cnt == 4)
                {
                    inr = 1;
                    sta = t.x;
                }
                else if(inr && cnt != 4)
                {
                    inr = 0;
                    res += t.x - sta;
                }
            }
        }
    }

    printf("%lld\n", res);
    return 0;
}

Compilation message

2016_ho_t4.cpp: In function 'int main()':
2016_ho_t4.cpp:145:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(!(a[d] < com.size() && com[a[d]] == p))
                  ~~~~~^~~~~~~~~~~~
2016_ho_t4.cpp:171:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < v.size(); j++)
                        ~~^~~~~~~~~~
2016_ho_t4.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%s", &n, &k, str);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
2016_ho_t4.cpp:199:32: warning: 'sta' may be used uninitialized in this function [-Wmaybe-uninitialized]
                     res += t.x - sta;
                            ~~~~^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2720 KB Output is correct
3 Correct 4 ms 2732 KB Output is correct
4 Correct 4 ms 2732 KB Output is correct
5 Correct 4 ms 2796 KB Output is correct
6 Correct 4 ms 2796 KB Output is correct
7 Correct 4 ms 2864 KB Output is correct
8 Correct 4 ms 2864 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 4 ms 2904 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 2904 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 3028 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 4 ms 3028 KB Output is correct
17 Correct 4 ms 3028 KB Output is correct
18 Correct 5 ms 3028 KB Output is correct
19 Correct 4 ms 3028 KB Output is correct
20 Correct 4 ms 3028 KB Output is correct
21 Correct 5 ms 3028 KB Output is correct
22 Correct 5 ms 3028 KB Output is correct
23 Correct 5 ms 3028 KB Output is correct
24 Correct 4 ms 3028 KB Output is correct
25 Correct 4 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2720 KB Output is correct
3 Correct 4 ms 2732 KB Output is correct
4 Correct 4 ms 2732 KB Output is correct
5 Correct 4 ms 2796 KB Output is correct
6 Correct 4 ms 2796 KB Output is correct
7 Correct 4 ms 2864 KB Output is correct
8 Correct 4 ms 2864 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 4 ms 2904 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 2904 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 3028 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 4 ms 3028 KB Output is correct
17 Correct 4 ms 3028 KB Output is correct
18 Correct 5 ms 3028 KB Output is correct
19 Correct 4 ms 3028 KB Output is correct
20 Correct 4 ms 3028 KB Output is correct
21 Correct 5 ms 3028 KB Output is correct
22 Correct 5 ms 3028 KB Output is correct
23 Correct 5 ms 3028 KB Output is correct
24 Correct 4 ms 3028 KB Output is correct
25 Correct 4 ms 3028 KB Output is correct
26 Correct 5 ms 3028 KB Output is correct
27 Correct 7 ms 3044 KB Output is correct
28 Correct 13 ms 3428 KB Output is correct
29 Correct 46 ms 4828 KB Output is correct
30 Correct 52 ms 5588 KB Output is correct
31 Correct 60 ms 8408 KB Output is correct
32 Correct 64 ms 8408 KB Output is correct
33 Correct 107 ms 8408 KB Output is correct
34 Correct 73 ms 8408 KB Output is correct
35 Correct 83 ms 8408 KB Output is correct
36 Correct 76 ms 8408 KB Output is correct
37 Correct 68 ms 8408 KB Output is correct
38 Correct 75 ms 8408 KB Output is correct
39 Correct 76 ms 8408 KB Output is correct
40 Correct 69 ms 8408 KB Output is correct
41 Correct 79 ms 8408 KB Output is correct
42 Correct 74 ms 8408 KB Output is correct
43 Correct 96 ms 8408 KB Output is correct
44 Correct 82 ms 8408 KB Output is correct
45 Correct 74 ms 8408 KB Output is correct
46 Correct 60 ms 8408 KB Output is correct
47 Correct 82 ms 8408 KB Output is correct
48 Correct 83 ms 9804 KB Output is correct
49 Correct 55 ms 9804 KB Output is correct
50 Correct 74 ms 9804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2720 KB Output is correct
3 Correct 4 ms 2732 KB Output is correct
4 Correct 4 ms 2732 KB Output is correct
5 Correct 4 ms 2796 KB Output is correct
6 Correct 4 ms 2796 KB Output is correct
7 Correct 4 ms 2864 KB Output is correct
8 Correct 4 ms 2864 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 4 ms 2904 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 2904 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 3028 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 4 ms 3028 KB Output is correct
17 Correct 4 ms 3028 KB Output is correct
18 Correct 5 ms 3028 KB Output is correct
19 Correct 4 ms 3028 KB Output is correct
20 Correct 4 ms 3028 KB Output is correct
21 Correct 5 ms 3028 KB Output is correct
22 Correct 5 ms 3028 KB Output is correct
23 Correct 5 ms 3028 KB Output is correct
24 Correct 4 ms 3028 KB Output is correct
25 Correct 4 ms 3028 KB Output is correct
26 Correct 5 ms 9804 KB Output is correct
27 Incorrect 4 ms 9804 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2720 KB Output is correct
3 Correct 4 ms 2732 KB Output is correct
4 Correct 4 ms 2732 KB Output is correct
5 Correct 4 ms 2796 KB Output is correct
6 Correct 4 ms 2796 KB Output is correct
7 Correct 4 ms 2864 KB Output is correct
8 Correct 4 ms 2864 KB Output is correct
9 Correct 3 ms 2900 KB Output is correct
10 Correct 4 ms 2904 KB Output is correct
11 Correct 4 ms 2904 KB Output is correct
12 Correct 4 ms 2904 KB Output is correct
13 Correct 4 ms 2904 KB Output is correct
14 Correct 4 ms 3028 KB Output is correct
15 Correct 4 ms 3028 KB Output is correct
16 Correct 4 ms 3028 KB Output is correct
17 Correct 4 ms 3028 KB Output is correct
18 Correct 5 ms 3028 KB Output is correct
19 Correct 4 ms 3028 KB Output is correct
20 Correct 4 ms 3028 KB Output is correct
21 Correct 5 ms 3028 KB Output is correct
22 Correct 5 ms 3028 KB Output is correct
23 Correct 5 ms 3028 KB Output is correct
24 Correct 4 ms 3028 KB Output is correct
25 Correct 4 ms 3028 KB Output is correct
26 Correct 5 ms 3028 KB Output is correct
27 Correct 7 ms 3044 KB Output is correct
28 Correct 13 ms 3428 KB Output is correct
29 Correct 46 ms 4828 KB Output is correct
30 Correct 52 ms 5588 KB Output is correct
31 Correct 60 ms 8408 KB Output is correct
32 Correct 64 ms 8408 KB Output is correct
33 Correct 107 ms 8408 KB Output is correct
34 Correct 73 ms 8408 KB Output is correct
35 Correct 83 ms 8408 KB Output is correct
36 Correct 76 ms 8408 KB Output is correct
37 Correct 68 ms 8408 KB Output is correct
38 Correct 75 ms 8408 KB Output is correct
39 Correct 76 ms 8408 KB Output is correct
40 Correct 69 ms 8408 KB Output is correct
41 Correct 79 ms 8408 KB Output is correct
42 Correct 74 ms 8408 KB Output is correct
43 Correct 96 ms 8408 KB Output is correct
44 Correct 82 ms 8408 KB Output is correct
45 Correct 74 ms 8408 KB Output is correct
46 Correct 60 ms 8408 KB Output is correct
47 Correct 82 ms 8408 KB Output is correct
48 Correct 83 ms 9804 KB Output is correct
49 Correct 55 ms 9804 KB Output is correct
50 Correct 74 ms 9804 KB Output is correct
51 Correct 5 ms 9804 KB Output is correct
52 Incorrect 4 ms 9804 KB Output isn't correct
53 Halted 0 ms 0 KB -