답안 #91263

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91263 2018-12-26T19:00:39 Z inom UFO (IZhO14_ufo) C++14
60 / 100
2000 ms 218308 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>

#define fi first
#define se second
#define new new228
#define pb push_back
#define rank rank228
#define int long long
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
 
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma warning(disable : 4996)
 
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // st.oreder_of_key();

const int N = 1000100;
const int INF = 1e9 + 7;
const int MAXN = 4 * N;
const int MOD = 998244353;
 
int TN = 1;

int n, m, r, k, p;
vector<vector<int>> a;
set<int> column[N], row[N];
pair<char, pair<int, int>> Q[N];

void subtask1() {
    for (int i = 1; i <= k; i++) {
        char c; int x, h;
        c = Q[i].fi, x = Q[i].se.fi, h = Q[i].se.se;
        if (c == 'W' || c == 'E') {
            if (c == 'W') {
                int cnt = r, j = 1;
                while (j <= m && cnt > 0) {
                    if (a[x][j] >= h) {
                        a[x][j]--; cnt--;
                    }
                    j++;
                }    
            }
            else {
                int cnt = r, j = m;
                while (j >= 1 && cnt > 0) {
                    if (a[x][j] >= h) {
                        a[x][j]--; cnt--;
                    }
                    j--;
                }
            }
        }
        else {
            if (c == 'N') {
                int cnt = r, j = 1;
                while (j <= n && cnt > 0) {
                    if (a[j][x] >= h) {
                        a[j][x]--; cnt--;
                    }
                    j++;
                }
            }
            else {
                int cnt = r, j = n;
                while (j >= 1 && cnt > 0) {
                    if (a[j][x] >= h) {
                        a[j][x]--; cnt--;
                    }
                    j--;
                }
            }
        }
    }
    int ans = 0; p--;
    for (int i = 1; i + p <= n; i++) {
        for (int j = 1; j + p <= m; j++) {
            int sum = 0;
            for (int u = i; u <= i + p; u++) {
                for (int v = j; v <= j + p; v++) {
                    sum += a[u][v];
                }
            }
            ans = max(ans, sum);
        }
    }
    printf("%lld\n", ans);
    exit(false);
}

void subtask2() {
    /*for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (a[i][j]) {
                column[i].insert(j);
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (a[j][i]) {
                row[i].insert(j);
            }
        }
    }
    /*for (int i = 1; i <= n; i++) {
        cout << i << " ";
        for (auto j: column[i]) {
            cout << j << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    for (int qs = 1; qs <= k; qs++) {
        char c; int x, h;
        c = Q[qs].fi; x = Q[qs].se.fi; h = Q[qs].se.se;
        // cout << c << " " << x << " " << h << "\n";
        if (c == 'W') {
            int cnt = 0;
            vector<int> tmp;
            while (cnt < r && sz(column[x]) > 0) {
                int cur = *column[x].begin();
                column[x].erase(column[x].begin());
                if (a[x][cur] > 0) {
                    a[x][cur]--; cnt++;
                    if (a[x][cur] > 0) 
                        tmp.pb(cur);
                }
            }
            for (auto i: tmp) {
                column[x].insert(i);
            }
        }
        if (c == 'E') {
            int cnt = 0;
            vector<int> tmp;
            while (cnt < r && sz(column[x]) > 0) {
                int cur = *column[x].rbegin();
                column[x].erase(--column[x].end());
                if (a[x][cur] > 0) {
                    a[x][cur]--; cnt++;
                    if (a[x][cur] > 0)
                        tmp.pb(cur);
                }
            }
            for (auto i: tmp) {
                column[x].insert(i);
            }
        }
        if (c == 'N') {
            int cnt = 0;
            vector<int> tmp;
            while (cnt < r && sz(row[x]) > 0) {
                int cur = *row[x].begin();
                // cout << x << " " << cur << " " << a[x][cur] << "\n";
                row[x].erase(row[x].begin());
                if (a[cur][x] > 0) {
                    a[cur][x]--; cnt++;
                    if (a[cur][x] > 0) 
                        tmp.pb(cur);
                }
            }
            for (auto i: tmp) {
                row[x].insert(i);
            }
        }
        if (c == 'S') {
            int cnt = 0;
            vector<int> tmp;
            while (cnt < r && sz(row[x]) > 0) {
                int cur = *row[x].rbegin();
                row[x].erase(--row[x].end());
                if (a[cur][x] > 0) {
                    a[cur][x]--; cnt++;
                    if (a[cur][x] > 0) {
                        tmp.pb(cur);
                    }
                }
            }
            for (auto i: tmp) {
                row[x].insert(i);
            }
        }
        /*
        for (int l = 1; l <= n; l++) {
            for (int j = 1; j <= m; j++) {
                cout << a[l][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        */
    }
    /*for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << a[i][j] << " ";
        }
        cout << endl;
    }
    cout << endl;*/
    int ans = 0; p--;
    for (int i = 1; i + p <= n; i++) {
        for (int j = 1; j + p <= m; j++) {
            int sum = 0;
            for (int u = i; u <= i + p; u++) {
                for (int v = j; v <= j + p; v++) {
                    sum += a[u][v];
                }
            }
            ans = max(ans, sum);
        }
    }
    printf("%lld\n", ans);
    exit(false);
}

signed main() {
    // ios_base::sync_with_stdio(0);
    // in; out;  // cin >> TN;
    scanf("%lld %lld %lld %lld %lld", &n, &m, &r, &k, &p);
    a.resize(n + 1, vector<int>(m + 1, false));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            scanf("%lld", &a[i][j]);
        }
    }
    bool ok = true;
    for (int i = 1; i <= k; i++) {
        // scanf("%c %lld %lld\n", &Q[i].fi, &Q[i].se.fi, &Q[i].se.se);
        cin >> Q[i].fi >> Q[i].se.fi >> Q[i].se.se;
        if (Q[i].se.se > 1) {
            ok = false;
        }
    }
    if (!ok) {
        subtask1();
    } else {
        subtask2();
    }
    return 0;
 }

Compilation message

ufo.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable : 4996)
 
ufo.cpp: In function 'void subtask2()':
ufo.cpp:131:24: warning: variable 'h' set but not used [-Wunused-but-set-variable]
         char c; int x, h;
                        ^
ufo.cpp: In function 'int main()':
ufo.cpp:236:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %lld %lld %lld %lld", &n, &m, &r, &k, &p);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ufo.cpp:240:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &a[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 94200 KB Output is correct
2 Correct 85 ms 94388 KB Output is correct
3 Correct 82 ms 94620 KB Output is correct
4 Correct 80 ms 95008 KB Output is correct
5 Correct 103 ms 97024 KB Output is correct
6 Correct 186 ms 101488 KB Output is correct
7 Execution timed out 2040 ms 111672 KB Time limit exceeded
8 Execution timed out 2070 ms 113664 KB Time limit exceeded
9 Correct 749 ms 208016 KB Output is correct
10 Correct 808 ms 208976 KB Output is correct
11 Correct 683 ms 208976 KB Output is correct
12 Correct 807 ms 210520 KB Output is correct
13 Correct 1198 ms 218308 KB Output is correct
14 Correct 850 ms 218308 KB Output is correct
15 Execution timed out 2049 ms 218308 KB Time limit exceeded
16 Execution timed out 2059 ms 218308 KB Time limit exceeded
17 Execution timed out 2062 ms 218308 KB Time limit exceeded
18 Execution timed out 2072 ms 218308 KB Time limit exceeded
19 Execution timed out 2076 ms 218308 KB Time limit exceeded
20 Execution timed out 2063 ms 218308 KB Time limit exceeded