QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#413126#4231. Rafting TripishmealWA 1ms3476kbC++203.9kb2024-05-17 06:43:322024-05-17 06:43:34

Judging History

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

  • [2024-05-17 06:43:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2024-05-17 06:43:32]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define f first 
#define s second 
#define pb push_back

int r, c;
vector<string> vec;
map<pii, pii> graph;
map<pii, vector<pii>> rev_graph;
vector<pii> heads;
map<pii, map<pii, int>> sites;
vector<vector<int>> visited;
map<char, pii> dirs = {{'v', {1, 0}}, {'^', {-1, 0}}, {'<', {0, -1}}, {'>', {0, 1}}};

bool valid(int x, int y){
    return (x >= 0 && x < r && y >= 0 && y < c);
}

bool land(int x, int y){
    return (vec[x][y] == '.' || vec[x][y] == '#');
}

int dir1[] = {0, 0, 1, -1};
int dir2[] = {-1, 1, 0, 0};
int maxAm = 0;

void add_sites(pii curr, pii head){
    for(int i = 0; i < 4; i++){
        int x = curr.f + dir1[i];
        int y = curr.s + dir2[i];
        if(!valid(x, y)) continue;
        if(vec[x][y] == '#') sites[head][{x, y}]++;
    }
}

void remove_sites(pii curr, pii head){
    for(int i = 0; i < 4; i++){
        int x = curr.f + dir1[i];
        int y = curr.s + dir2[i];
        if(!valid(x, y)) continue;
        if(vec[x][y] == '#'){
            sites[head][{x, y}]--;
            if(sites[head][{x, y}] == 0) sites[head].erase({x, y});
        }
    }
}

void find_head(pii curr);
void comp_cycles(pii curr, pii head, int head_cnt);
void dfs(pii curr, pii head);

int main() {
	cin.tie(0)->sync_with_stdio(0);

    cin >> r >> c;
    for(int i = 0; i < r; i++){
        string str;
        cin >> str;
        vec.pb(str);
    }
    for(int i = 0; i < r; i++){
        for(int  j = 0; j < c; j++){
            if(land(i, j)) continue;
            graph[{i, j}] = {-1, -1};
            rev_graph[{i, j}] = {};
        }
    }
    for(int i = 0; i < r; i++){
        for(int  j = 0; j < c; j++){
            if(land(i, j)) continue;
            int x = i + dirs[vec[i][j]].f;
            int y = j + dirs[vec[i][j]].s;
            cout << "(" << i << ", " << j << ") (" << x << ", " << y << ")\n";
            if(!valid(x, y) || land(x, y)) continue;
            graph[{i, j}] = {x, y};
            rev_graph[{x, y}].pb({i, j});
        }
    }

    cout << endl;

    visited.assign(r, vector<int>(c, 0));
    for(auto p : graph){
        pii curr = p.f;
        if(visited[curr.f][curr.s]) continue;
        find_head(curr);
        cout << "\n";
    }

    cout << endl;
    //cout << heads.size() << "\n";

    // rev_graph is wrong
    for(int i = 0; i < heads.size(); i++){
        sites[heads[i]] = {};
        int h_cnt = 0;
        comp_cycles(heads[i], heads[i], h_cnt);
    }

    for(auto p : rev_graph){
        cout << "(" << p.f.f << ", " << p.f.s << "): ";
        for(auto p2 : p.s){
            cout << "(" << p2.f << ", " << p2.s << ") ";
        }

        cout << "\n";
    }

    cout << endl;

    for(int i = 0; i < heads.size(); i++){
        
        dfs(heads[i], heads[i]);
        //cout << "\n";
    }

    cout << maxAm << "\n";
}

void find_head(pii curr){
    if(visited[curr.f][curr.s] == 2) return;
    if(visited[curr.f][curr.s] == 1){
        heads.pb(curr);
        return;
    }
    cout << "(" << curr.f << ", " << curr.s << ") ";
    visited[curr.f][curr.s] = 1;
    if(graph[curr] != (pii){-1, -1}) find_head(graph[curr]);
    else heads.pb(curr);
    visited[curr.f][curr.s] = 2;
}

// mignt not be working
void comp_cycles(pii curr, pii head, int head_cnt){
    if(curr == head){
        if(head_cnt == 0) head_cnt++;
        else return;
    }
    add_sites(curr, head);
    if(curr != head){
        for(auto p : rev_graph[curr]){
            rev_graph[head].pb(p);
        }
    }
}

void dfs(pii curr, pii head){
    if(curr != head) add_sites(curr, head);
    //cout << "(" << curr.f << ", " << curr.s << "): " << sites[head].size() << "\n"; 
    maxAm = max(maxAm, (int)sites[head].size());
    for(auto p : rev_graph[curr]){
        dfs(p, head);
    }
    if(curr != head) remove_sites(curr, head);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3476kb

input:

5 6
v<<<#v
v#v<.>
>>v<<<
..v##^
#<<<.^

output:

(0, 0) (1, 0)
(0, 1) (0, 0)
(0, 2) (0, 1)
(0, 3) (0, 2)
(0, 5) (1, 5)
(1, 0) (2, 0)
(1, 2) (2, 2)
(1, 3) (1, 2)
(1, 5) (1, 6)
(2, 0) (2, 1)
(2, 1) (2, 2)
(2, 2) (3, 2)
(2, 3) (2, 2)
(2, 4) (2, 3)
(2, 5) (2, 4)
(3, 2) (4, 2)
(3, 5) (2, 5)
(4, 1) (4, 0)
(4, 2) (4, 1)
(4, 3) (4, 2)
(4, 5) (3, 5)

(0, 0...

result:

wrong answer 1st lines differ - expected: '4', found: '(0, 0) (1, 0)'