提出 #22669758
ソースコード 拡げる
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<unordered_map>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set>
#include<cmath>
#include <numeric>
#include <array>
#include<utility>
#include <complex>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#pragma region define
#define M_PI 3.141592653589793238
#define upperbound(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lowerbound(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,l,r) for(int i=l;i<r;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp(a,b) make_pair(a,b)
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) (lower_bound(h.begin(),h.end(),val)-h.begin())
#define upper(h,val) (upper_bound(h.begin(),h.end(),val)-h.begin())
#define vveb V<veb>
#define omajinai cin.tie(0);ios::sync_with_stdio(false);
#define endl "\n"
#define pb push_back
#pragma endregion
#pragma region Inner Class
int root(int x, vel& pa) {
if (pa[x] == -1) { return x; }
int ans = root(pa[x], pa); pa[x] = ans;
return ans;
}
bool mar(int x, int y, vel& pa) {
x = root(x, pa);
y = root(y, pa);
if (x != y) { pa[x] = y; }
return (x != y);
}
int gcd(int x, int y) {
if (x < y) { return gcd(y, x); }
if (y == 0) { return x; }
return gcd(y, x % y);
}
int lcm(int x, int y) {
x = abs(x); y = abs(y);
return x * (y / gcd(x, y));
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
vel dijk(V<V<pin>> way, int st, int inf) {
int n = way.size();
vel dist(n, inf); dist[st] = 0;
priority_queue<pin, vector<pin>, greater<pin>> pq;
pq.push(mkp(0, st));
veb is_checked(n, false);
while (!pq.empty()) {
pin x = pq.top(); pq.pop();
int pot = x.second;
if (!is_checked[pot]) {
is_checked[pot] = true;
for (auto y : way[pot]) {
int nex_dist = x.first + y.second;
int nex_pot = y.first;
if (dist[nex_pot] > nex_dist) {
dist[nex_pot] = nex_dist;
pq.push(mkp(nex_dist, y.first));
}
}
}
}
return dist;
}
V<V<pin>> make_w(vvel v) {
int n = v.size();
V<V<pin>> ret(n);
rep(i, n) {
for (int x : v[i]) {
ret[i].push_back(mkp(x, 1));
}
}
return ret;
}
void make_tree(vvel& chi, vel& par, int n) {
V<V<pin>> way(n);
rep(i, n - 1) {
int a, b; cin >> a >> b; a--; b--;
way[a].push_back(mkp(b, 1));
way[b].push_back(mkp(a, 1));
}
vel dist = dijk(way, 0, n + 1);
par = vel(n, -1);
chi = vvel(n);
rep(i, n) {
for (auto nex : way[i]) {
int pot = nex.first;
if (dist[pot] > dist[i]) { chi[i].push_back(pot); }
else { par[i] = pot; }
}
}
}
void pri(vel& v) {
if (v.size() == 0) { return; }
cout << v[0];
rep(i, v.size() - 1) { cout << " " << v[i + 1]; }
cout << endl;
return;
}
vvel disj_min(vel& v) {
int n = v.size();
vvel ret(22, vel(n));
ret[0] = v;
rep(i, 21) {
rep(j, n) {
int nex = j + (1 << i);
if (nex < n) {
ret[i + 1][j] = min(ret[i][j], ret[i][nex]);
}
else {
ret[i + 1][j] = ret[i][j];
}
}
}
return ret;
}
int find_min(vvel& dv, int l, int r) {
int i = 21;
while (l + (1 << i) > r) {
i--;
}
while (i >= 0) {
if (dv[i][l] > dv[i][r - (1 << i)]) {
l = r - (1 << i);
}
else {
r = l + (1 << i);
}
i--;
}
return l;
}
V<V<pin>> dbl(V<pin>& v) {
V<V<pin>> ans(20, V<pin>(v));
int n = v.size();
rep(i, 19) {
rep(j, n) {
ans[i + 1][j].first = ans[i][ans[i][j].first].first;
ans[i + 1][j].second = max(ans[i][j].second, ans[i][ans[i][j].first].second);
}
}
return ans;
}
int lca(int s, int t, int diff, V<V<pin>>& pa) {
if (diff < 0) { return lca(t, s, -diff, pa); }
int ans = 0;
rep(i, 19) {
if ((diff & (1 << i)) != 0) {
mmax(ans, pa[i][s].second);
s = pa[i][s].first;
}
}
for (int i = 19; i >= 0; i--) {
if (pa[i][s] != pa[i][t]) {
mmax(ans, pa[i][s].second);
s = pa[i][s].first;
mmax(ans, pa[i][t].second);
t = pa[i][t].first;
}
}
if (s != t) {
mmax(ans, pa[0][s].second);
mmax(ans, pa[0][t].second);
}
return ans;
}
void alp(int n, vel& pr) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
pr.push_back(i);
while (n % i == 0) { n /= i; }
}
}
if (n != 1) { pr.push_back(n); }
}
vel dx = { 0,0,-1,1,1,-1 };
vel dy = { 1,-1,0,0,1,1 };
#define all(a) a.begin(),a.end()
template<typename T>
void mk_uni(V<T>& a) {
std::sort(a.begin(), a.end());
a.erase(std::unique(a.begin(), a.end()), a.end());
}
/*#include <cstdint>
template <std::uint_fast64_t Modulus> class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
constexpr u64& value() noexcept { return a; }
constexpr const u64& value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
constexpr modint& operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
constexpr modint& operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
constexpr modint& operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
constexpr modint& operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
};*/
using mint = modint1000000007;
using vem = vector<mint>;
using vvem = vector<vem>;
#pragma region mint
mint mpow(mint a, int n) {
mint ans = 1;
while (n) {
if (n & 1) { ans *= a; }
a *= a; n /= 2;
}
return ans;
}
vem kai, inv_kai;
void make_kai(int n) {
kai = vem(n + 1, 1);
inv_kai = vem(n + 1, 1);
rep(i, n) { kai[i + 1] = kai[i] * (i + 1); }
inv_kai[n] = (mint)1 / kai[n];
for (int i = n; i > 0; i--) { inv_kai[i - 1] = inv_kai[i] * i; }
}
mint com(int n, int r) {
if (n < 0 || r < 0 || n < r) { return 0; }
return kai[n] * inv_kai[r] * inv_kai[n - r];
}
mint per(int n, int r) {
if (n < 0 || r < 0 || n < r) { return 0; }
return kai[n] * inv_kai[r];
}
#pragma endregion
string s;
int inf = 1e7;
pin f2(vel& x, vel& y) {
int sum = 0;
rep(i, 26) {
sum += x[i] + y[i];
x[i] *= 100; x[i] += i;
y[i] *= 100; y[i] += i;
}
sor(x); rev(x);
sor(y); rev(y);
int fi = sum - (x[0] / 100) - (y[0] / 100);
if (x[0] % 100 != y[0] % 100) { return mkp(fi, (int)0); }
x[0] /= 100; y[0] /= 100; x[1] /= 100; y[1] /= 100;
return mkp(sum - x[0] - y[0], min(x[0] - x[1], y[0] - y[1]));
}
int f1(vel& x) {
int sum = 0;
int mx = 0;
for (auto w : x) { sum += w; mmax(mx, w); }
return sum - mx;
}
int cnt[61];
bool sol(vvel& a, int x) {
veb exi(32, false);
exi[0] = true;
int n = a.size();
rep(i, n) {
int cnt = 0;
rep(j, 5) {
if (a[i][j] >= x) { cnt += (1 << j); }
}
exi[cnt] = true;
}
rep(i, 32) {
if (exi[i]) {
rep(j, 32) {
if (exi[j]) {
rep(k, 32) {
if (exi[k]) {
if ((i | j | k) == 31) {
return true;
}
}
}
}
}
}
}
return false;
}
int r, c;
int ind(int qr, int qc) { return qr * c + qc; }
vel sol(int p, int a, int b) {
int inva = modinv(a, p);
int invb = modinv(b, p);
vel ans;
int x = 1;
vel use(p, false);
while (!use[x]) {
ans.push_back(x); use[x] = true;
x *= a; x %= p;
}
x *= inva; x *= b; x %= p;
bool fl = true;
while (!use[x]) {
ans.push_back(x); use[x] = true;
int nex = x * b;
if (!fl) { nex = x * invb; }
nex %= p;
if (use[nex]) {
nex = x * inva; nex %= p;
fl = !fl;
}
x = nex;
}
if (ans.size() < p - 1 || (ans.back() != invb && ans.back() != inva && ans.back() != a && ans.back() != b)) { return { -1000 }; }
ans.push_back(1);
return ans;
}
signed main() {
int h, w; cin >> h >> w;
dsu d(h + w);
vvel way(h + w);
rep(i, h) {
string s; cin >> s;
rep(j, w) {
if (s[j] == 'R') {
d.merge(i, j + h);
way[i].push_back(j + h);
way[j + h].push_back(i);
}
}
}
V<V<signed>> gr = d.groups();
int hh = 0, ww = 0, ex = 0;
V<V<pin>> ansh,answ;
vveb use(2, veb(h+w, false));
for (auto v : gr) {
if (v.size() >= 2) {
int vh = 0, vw = 0;
int rh = 0;
int rw = 0;
for (auto x : v) {
if (x < h) { vh++; rh = x; }
else { vw++; rw = x; }
}
hh += vh - 1;
ww += vw - 1;
ex++;
rep(fl, 2) {
V<pin> res;
int rt = rh;
if (fl == 1) { rt = rw; }
queue<int> q;
q.push(rt); use[fl][rt] = true;
while (!q.empty()) {
int st = q.front(); q.pop();
for (auto nex : way[st]) {
if (!use[fl][nex]) {
use[fl][nex] = true;
res.push_back(mkp(st, nex));
q.push(nex);
}
}
}
rev(res);
if (fl == 0) { ansh.push_back(res); }
else { answ.push_back(res); }
}
}
}
cout << hh + ww + ex << endl;
hh = h - hh;
ww = w - ww;
int ans = h*w+1;
int ans_i = 0;
rep(i, ex + 1) {
if (ans > (hh - i) * (ww - ex + i)) {
ans_i = i;
ans = (hh - i) * (ww - ex + i);
}
}
int cnt = 0;
for (auto v : gr) {
if (v.size() >= 2) {
V<pin> res = answ[cnt];
if (ans_i == 0) {
res = ansh[cnt];
}
for (auto pinx : res) {
if (pinx.second < h) { cout << "X "; swap(pinx.first, pinx.second);}
else { cout << "Y "; }
cout << pinx.first + 1 << " " << pinx.second - h + 1 << endl;
}
cnt++;
}
}
return 0;
}
提出情報
コンパイルエラー
./Main.cpp:23: warning: ignoring #pragma region define [-Wunknown-pragmas]
23 | #pragma region define
|
./Main.cpp:24: warning: "M_PI" redefined
24 | #define M_PI 3.141592653589793238
|
In file included from /usr/include/c++/9/cmath:45,
from ./Main.cpp:15:
/usr/include/math.h:777: note: this is the location of the previous definition
777 | # define M_PI 3.14159265358979323846 /* pi */
|
./Main.cpp:49: warning: ignoring #pragma endregion [-Wunknown-pragmas]
49 | #pragma endregion
|
./Main.cpp:50: warning: ignoring #pragma region Inner [-Wunknown-pragmas]
50 | #pragma region Inner Class
|
./Main.cpp:282: warning: ignoring #pragma region mint [-Wunknown-pragmas]
282 | #pragma region mint
|
./Main.cpp:307: warning: ignoring #pragma endregion [-Wunknown-pragmas]
307 | #pragma endregion
|
./Main.cpp: In function ‘void pri(std::vector<long long int>&)’:
./Main.cpp:30:31: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
30 | #define rep(i,n) for(int i=0;i<n;i++)
......
136 | rep(i, v.size() - 1) { cout << " " << v[i + 1]; }
| ~~~~~~~~~~~~~~~
./Main.cpp:136:2: note: in expansion of macro ‘rep’
136 | rep(i, v.size() - 1) { cout << " " << v[i + 1]; }
| ^~~
./Main.cpp: In function ‘std::vector<long long int> sol(long long int, long long int, long long int)’:
./Main.cpp:384:17: warning: comparison of integer expressions of different signedness: ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} and ‘long long int’ [-Wsign-compare]
384 | if (ans.size() < p - 1 || (ans.back() != invb && ans.back() != inva && ans.back() != a && ans.back() != b)) { return { -1000 }; }
| ~~~~~~~~~~~^~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
700 / 700 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
| All |
in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in48.txt, in49.txt, in50.txt, in51.txt, in52.txt, in53.txt, in54.txt, in55.txt, in56.txt, in57.txt, in58.txt, in59.txt, in60.txt, in61.txt, in62.txt, in63.txt, in64.txt, in65.txt, in66.txt, in67.txt, sample_01.txt, sample_02.txt, sample_03.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| in01.txt |
AC |
12 ms |
3592 KiB |
| in02.txt |
AC |
2 ms |
3504 KiB |
| in03.txt |
AC |
2 ms |
3440 KiB |
| in04.txt |
AC |
2 ms |
3488 KiB |
| in05.txt |
AC |
2 ms |
3636 KiB |
| in06.txt |
AC |
1 ms |
3644 KiB |
| in07.txt |
AC |
98 ms |
3748 KiB |
| in08.txt |
AC |
98 ms |
4088 KiB |
| in09.txt |
AC |
98 ms |
4064 KiB |
| in10.txt |
AC |
95 ms |
4104 KiB |
| in11.txt |
AC |
98 ms |
4096 KiB |
| in12.txt |
AC |
99 ms |
4144 KiB |
| in13.txt |
AC |
100 ms |
4148 KiB |
| in14.txt |
AC |
101 ms |
4288 KiB |
| in15.txt |
AC |
101 ms |
4616 KiB |
| in16.txt |
AC |
102 ms |
4852 KiB |
| in17.txt |
AC |
103 ms |
5416 KiB |
| in18.txt |
AC |
106 ms |
6720 KiB |
| in19.txt |
AC |
112 ms |
9612 KiB |
| in20.txt |
AC |
328 ms |
132544 KiB |
| in21.txt |
AC |
5 ms |
3628 KiB |
| in22.txt |
AC |
97 ms |
4016 KiB |
| in23.txt |
AC |
99 ms |
4092 KiB |
| in24.txt |
AC |
99 ms |
4160 KiB |
| in25.txt |
AC |
100 ms |
4204 KiB |
| in26.txt |
AC |
99 ms |
4120 KiB |
| in27.txt |
AC |
99 ms |
4372 KiB |
| in28.txt |
AC |
98 ms |
4152 KiB |
| in29.txt |
AC |
98 ms |
4116 KiB |
| in30.txt |
AC |
97 ms |
4220 KiB |
| in31.txt |
AC |
91 ms |
4096 KiB |
| in32.txt |
AC |
96 ms |
4060 KiB |
| in33.txt |
AC |
101 ms |
4100 KiB |
| in34.txt |
AC |
5 ms |
3556 KiB |
| in35.txt |
AC |
99 ms |
4040 KiB |
| in36.txt |
AC |
103 ms |
5172 KiB |
| in37.txt |
AC |
98 ms |
4128 KiB |
| in38.txt |
AC |
100 ms |
4572 KiB |
| in39.txt |
AC |
98 ms |
4208 KiB |
| in40.txt |
AC |
101 ms |
4612 KiB |
| in41.txt |
AC |
100 ms |
4600 KiB |
| in42.txt |
AC |
7 ms |
3552 KiB |
| in43.txt |
AC |
100 ms |
4016 KiB |
| in44.txt |
AC |
124 ms |
17812 KiB |
| in45.txt |
AC |
103 ms |
5960 KiB |
| in46.txt |
AC |
100 ms |
4384 KiB |
| in47.txt |
AC |
99 ms |
4136 KiB |
| in48.txt |
AC |
7 ms |
3620 KiB |
| in49.txt |
AC |
148 ms |
29000 KiB |
| in50.txt |
AC |
122 ms |
17288 KiB |
| in51.txt |
AC |
107 ms |
7728 KiB |
| in52.txt |
AC |
100 ms |
4436 KiB |
| in53.txt |
AC |
99 ms |
4176 KiB |
| in54.txt |
AC |
4 ms |
3632 KiB |
| in55.txt |
AC |
2 ms |
3552 KiB |
| in56.txt |
AC |
99 ms |
4212 KiB |
| in57.txt |
AC |
98 ms |
4288 KiB |
| in58.txt |
AC |
93 ms |
4188 KiB |
| in59.txt |
AC |
100 ms |
4336 KiB |
| in60.txt |
AC |
4 ms |
3656 KiB |
| in61.txt |
AC |
2 ms |
3500 KiB |
| in62.txt |
AC |
3 ms |
3552 KiB |
| in63.txt |
AC |
2 ms |
3548 KiB |
| in64.txt |
AC |
2 ms |
3436 KiB |
| in65.txt |
AC |
2 ms |
3484 KiB |
| in66.txt |
AC |
2 ms |
3456 KiB |
| in67.txt |
AC |
2 ms |
3620 KiB |
| sample_01.txt |
AC |
2 ms |
3552 KiB |
| sample_02.txt |
AC |
2 ms |
3508 KiB |
| sample_03.txt |
AC |
2 ms |
3500 KiB |