QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#673571#5414. Stop, Yesterday Please No MorecabbageaCompile Error//C++205.4kb2024-10-25 00:14:312024-10-25 00:14:31

Judging History

你现在查看的是最新测评结果

  • [2024-10-25 00:14:31]
  • 评测
  • [2024-10-25 00:14:31]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    cin >> s;
    int u = 1, d = n, l = 1, r = m;
    bool emp = false;
    for (auto x : s) {
        if ( x == 'U' ) {
            if ( d == 1 ) {
                emp = true;
                break;
            } else {
                u = max(1ll, u - 1), d--;
            }
        } else if ( x == 'D' ) {
            if ( u == n ) {
                emp = true;
                break;
            } else {
                u++, d = min(n, d + 1);
            }
        } else if ( x == 'L' ) {
            if ( r == 1 ) {
                emp = true;
                break;#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    cin >> s;
    int u = 1, d = n, l = 1, r = m;
    bool emp = false;
    for (auto x : s) {
        if ( x == 'U' ) {
            if ( d == 1 ) {
                emp = true;
                break;
            } else {
                u = max(1ll, u - 1), d--;
            }
        } else if ( x == 'D' ) {
            if ( u == n ) {
                emp = true;
                break;
            } else {
                u++, d = min(n, d + 1);
            }
        } else if ( x == 'L' ) {
            if ( r == 1 ) {
                emp = true;
                break;
            } else {
                l = max(1ll, l - 1), r--;
            }
        } else if ( x == 'R' ) {
            if ( l == n ) {
                emp = true;
                break;
            } else {
                l++, r = min(m, r + 1);
            }
        }
    }
    if (emp) {
        if ( k == 0 ) {
            cout << n * m << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }
    int lv = ( d - u + 1 ) * ( r - l + 1 );
    if ( lv < k ) {
        cout << 0 << endl;
        return;
    }
    reverse(s.begin(), s.end());
    set<PII> st;
    PII p = {0, 0};
    st.insert(p);
    for (auto x : s) {
        if ( x == 'U' ) p.x--;
        else if ( x == 'D' ) p.x++;
        else if ( x == 'L' ) p.y--;
        else if ( x == 'R' ) p.y++;
        st.insert(p);
    }
    int dx = 1 - u + n, dy = 1 - l + m;
    vector< vector<int> > g( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    vector< vector<int> > sg( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    for (auto x : st) {
        x.x += dx, x.y += dy;
        if ( x.x > n + (d - u) || x.y > m + (r - l) ) continue;
        g[x.x][x.y] = 1;
    }
    for (int i = 1; i <= n + (d - u); i++) {
        for (int j = 1; j <= m + (r - l); j++) {
            sg[i][j] = sg[i - 1][j] + sg[i][j - 1] - sg[i - 1][j - 1] + g[i][j];
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int s = sg[ i + (d - u) ][ j + (r - l) ] - sg[ i - 1 ][ j + (r - l) ] 
                - sg[ i + (d - u) ][ j - 1 ] + sg[ i - 1 ][ j - 1 ];
            if ( lv - s == k ) cnt++;
        }
    }
    cout << cnt << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

            } else {
                l = max(1ll, l - 1), r--;
            }
        } else if ( x == 'R' ) {
            if ( l == n ) {
                emp = true;
                break;
            } else {
                l++, r = min(m, r + 1);
            }
        }
    }
    if (emp) {
        if ( k == 0 ) {
            cout << n * m << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }
    int lv = ( d - u + 1 ) * ( r - l + 1 );
    if ( lv < k ) {
        cout << 0 << endl;
        return;
    }
    reverse(s.begin(), s.end());
    set<PII> st;
    PII p = {0, 0};
    st.insert(p);
    for (auto x : s) {
        if ( x == 'U' ) p.x--;
        else if ( x == 'D' ) p.x++;
        else if ( x == 'L' ) p.y--;
        else if ( x == 'R' ) p.y++;
        st.insert(p);
    }
    int dx = 1 - u + n, dy = 1 - l + m;
    vector< vector<int> > g( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    vector< vector<int> > sg( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    for (auto x : st) {
        x.x += dx, x.y += dy;
        if ( x.x > n + (d - u) || x.y > m + (r - l) ) continue;
        g[x.x][x.y] = 1;
    }
    for (int i = 1; i <= n + (d - u); i++) {
        for (int j = 1; j <= m + (r - l); j++) {
            sg[i][j] = sg[i - 1][j] + sg[i][j - 1] - sg[i - 1][j - 1] + g[i][j];
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int s = sg[ i + (d - u) ][ j + (r - l) ] - sg[ i - 1 ][ j + (r - l) ] 
                - sg[ i + (d - u) ][ j - 1 ] + sg[ i - 1 ][ j - 1 ];
            if ( lv - s == k ) cnt++;
        }
    }
    cout << cnt << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

Details

answer.code:34:23: error: stray ‘#’ in program
   34 |                 break;#include <bits/stdc++.h>
      |                       ^
answer.code: In function ‘void solve()’:
answer.code:34:33: error: ‘bits’ was not declared in this scope
   34 |                 break;#include <bits/stdc++.h>
      |                                 ^~~~
answer.code:34:38: error: ‘stdc’ was not declared in this scope; did you mean ‘std’?
   34 |                 break;#include <bits/stdc++.h>
      |                                      ^~~~
      |                                      std
answer.code:34:24: error: ‘include’ was not declared in this scope
   34 |                 break;#include <bits/stdc++.h>
      |                        ^~~~~~~
answer.code:39:1: error: expected primary-expression before ‘using’
   39 | using namespace std;
      | ^~~~~
answer.code:42:14: error: a function-definition is not allowed here before ‘{’ token
   42 | void solve() {
      |              ^
answer.code:128:12: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  128 | signed main() {
      |            ^~
answer.code:128:12: note: remove parentheses to default-initialize a variable
  128 | signed main() {
      |            ^~
      |            --
answer.code:128:12: note: or replace parentheses with braces to value-initialize a variable
answer.code:128:15: error: a function-definition is not allowed here before ‘{’ token
  128 | signed main() {
      |               ^