Submission #983367

#TimeUsernameProblemLanguageResultExecution timeMemory
983367Jawad_Akbar_JJMars (APIO22_mars)C++17
14 / 100
11 ms4364 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; bool seen[50][50]; int N; vector<string> A; bool valid(int i,int j){ if (i >= 0 and i < N and j >= 0 and j < N and !seen[i][j] and A[i][j] == '1'){ seen[i][j] = true; return true; } return false; } void bfs(int si,int sj){ queue<pair<int,int>> Q; Q.push({si,sj}); seen[si][sj] = 1; while (!Q.empty()){ auto [i,j] = Q.front(); Q.pop(); if (valid(i-1,j)) Q.push({i-1,j}); if (valid(i+1,j)) Q.push({i+1,j}); if (valid(i,j+1)) Q.push({i,j+1}); if (valid(i,j-1)) Q.push({i,j-1}); } } string Ans(string s){ for (int i=0;i<50;i++) for (int j=0;j<50;j++) seen[i][j] = false; A.clear(); for (int i=0;i<N;i++){ string ss; for (int j=0;j<N;j++) ss += s[i * N + j]; A.push_back(ss); } int ans = 0; for (int i=0;i<N;i++){ for (int j=0;j<N;j++) if (!seen[i][j] and A[i][j] == '1') bfs(i,j),ans++; } for (int i=0;i<100;i++) s[i] = '0'; int cur = 0; while (ans){ char c = char(ans % 2 + 48); s[cur++] = c; ans >>= 1; } return s; } string process(vector <vector<string>> a, int i, int j, int k, int n){ N = n + n + 1; int m = 2 * (n - k - 1); int M = N - m; int K = M - 2; if (i == m and j == m){ string s; for (int i=1;i<=100;i++) s += '0'; int cur = 0; /////////////////////// row 1 s[cur++] = a[0][0][0]; s[cur++] = a[0][1][0]; for (int i=0;i<K;i++) s[cur++] = a[0][2][i]; /////////////////////// row 2 s[cur++] = a[1][0][0]; s[cur++] = a[1][1][0]; for (int i=0;i<K;i++) s[cur++] = a[1][2][i]; /////////////////////// row 3 for (int i=0;i<K;i++){ s[cur++] = a[2][0][i]; s[cur++] = a[2][1][i]; for (int j=0;j<K;j++) s[cur++] = a[2][2][i * K + j]; } if (i == 0 and j == 0) return Ans(s); return s; } if (i == m){ string s; for (int i=1;i<=100;i++) s += '0'; s[0] = a[0][0][0]; s[1] = a[1][0][0]; for (int i=0;i<K;i++) s[2 + i] = a[2][0][i]; return s; } if (j == m){ string s; for (int i=1;i<=100;i++) s += '0'; s[0] = a[0][0][0]; s[1] = a[0][1][0]; for (int i=0;i<K;i++) s[2 + i] = a[0][2][i]; return s; } return a[0][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...