submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s716789180
p03725
C++
#include <bits/stdc++.h> using namespace std; int n, m, k, step=0; pair<int, int> s, bas; vector< vector<char> > vec; vector< vector<int> > ans; queue< pair<int, int> > q; vector< vector<int> > visit; void dene(); void kir(); void kir(){ while(!q.empty()){ auto p=q.front(); q.pop(); int x=p.first, y=p.second; int cx=x, cy=y; int i=0; //cout << cx << " " << cy << "\n"; while(cx>0 and k>i){ cx--; if(vec[cx][y]=='#'){ vec[cx][y]='.'; i++; } //cout << cx << " " << cy << "\n"; } i=0; cx=x; while(n-1>cx and k>i){ cx++; if(vec[cx][y]=='#'){ vec[cx][y]='.'; i++; } } i=0; cy=y; while(cy>0 and k>i){ cy--; if(vec[x][cy]=='#'){ vec[x][cy]='.'; i++; } } i=0; cy=y; while(n-1>cy and k>i){ cy++; if(vec[x][cy]=='#'){ vec[x][cy]='.'; i++; } } s={x, y}; dene(); } } void dene(){ int x=s.first; int y=s.second; visit[x][y]=1; bool sol=true, sag=true, yukari=true, asagi=true; ++step; bool islem=false; for(int i=1;k>=i;i++){ if(x+i<n and vec[x+i][y]=='.' and sag and !visit[x+i][y]){ ans[x+i][y]=step; q.push({x+i, y}); visit[x+i][y]=1; islem=true; } if(y+i<m and vec[x][y+i]=='.' and yukari and !visit[x][y+i]){ ans[x][y+i]=step; q.push({x, y+i}); visit[x][y+i]=1; islem=true; } if(x-i>=0 and vec[x-i][y]=='.' and sol and !visit[x-i][y]){ ans[x-i][y]=step; q.push({x-i, y}); visit[x-i][y]=1; islem=true; } if(y-i>=0 and vec[x][y-i]=='.' and asagi and !visit[x][y-i]){ ans[x][y-i]=step; q.push({x, y-i}); visit[x][y-i]=1; islem=true; } if(x+i<n and vec[x+i][y]=='#'){ sag=false; } if(x-i>=0 and vec[x-i][y]=='#'){ sol=false; } if(y+i<n and vec[x][y+i]=='#'){ yukari=false; } if(y-i>0 and vec[x][y-i]=='#'){ asagi=false; } } if(islem){ kir(); } else if(s==bas){ q.push({x, y}); kir(); } } int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> k; vec.resize(n, vector<char>(m)); ans.resize(n, vector<int>(m, INF)); visit.resize(n, vector<int>(m, 0)); for(int i=0;n>i;i++){ for(int j=0;m>j;j++){ cin >> vec[i][j]; if(vec[i][j]=='S'){ s={i, j}; ans[i][j]=0; } } } bas=s; dene();/* for(int i=0;n>i;i++){ for(int j=0;m>j;j++){ if(ans[i][j]==INF){ cout << "U" << ' '; continue; } cout << ans[i][j] << " "; } cout << "\n"; }*/ int mini=INF; for(int i=0;n>i;i++){ mini=min(mini, ans[i][0]); mini=min(mini, ans[i][m-1]); } for(int i=0;m>i;i++){ mini=min(mini, ans[0][i]); mini=min(mini, ans[n-1][i]); } cout << mini; }
a.cc: In function 'void dene()': a.cc:50:37: error: reference to 'visit' is ambiguous 50 | int x=s.first; int y=s.second; visit[x][y]=1; | ^~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80, from a.cc:1: /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:53:52: error: reference to 'visit' is ambiguous 53 | if(x+i<n and vec[x+i][y]=='.' and sag and !visit[x+i][y]){ | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:54:53: error: reference to 'visit' is ambiguous 54 | ans[x+i][y]=step; q.push({x+i, y}); visit[x+i][y]=1; islem=true; | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:56:55: error: reference to 'visit' is ambiguous 56 | if(y+i<m and vec[x][y+i]=='.' and yukari and !visit[x][y+i]){ | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:57:53: error: reference to 'visit' is ambiguous 57 | ans[x][y+i]=step; q.push({x, y+i}); visit[x][y+i]=1; islem=true; | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:59:53: error: reference to 'visit' is ambiguous 59 | if(x-i>=0 and vec[x-i][y]=='.' and sol and !visit[x-i][y]){ | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:60:53: error: reference to 'visit' is ambiguous 60 | ans[x-i][y]=step; q.push({x-i, y}); visit[x-i][y]=1; islem=true; | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:62:55: error: reference to 'visit' is ambiguous 62 | if(y-i>=0 and vec[x][y-i]=='.' and asagi and !visit[x][y-i]){ | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc:63:53: error: reference to 'visit' is ambiguous 63 | ans[x][y-i]=step; q.push({x, y-i}); visit[x][y-i]=1; islem=true; | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~ a.cc: In function 'int main()': a.cc:89:34: error: 'INF' was not declared in this scope 89 | ans.resize(n, vector<int>(m, INF)); visit.resize(n, vector<int>(m, 0)); | ^~~ a.cc:89:41: error: reference to 'visit' is ambiguous 89 | ans.resize(n, vector<int>(m, INF)); visit.resize(n, vector<int>(m, 0)); | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:6:52: note: 'std::vector<std::vector<int> > visit' 6 | queue< pair<int, int> > q; vector< vector<int> > visit; | ^~~~~
s980458609
p03725
C++
#include<iomanip> #include<limits> #include<thread> #include<utility> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> #include<cassert> #include<random> #include<chrono> #include<unordered_map> #include<fstream> #include<list> #include<functional> #include<bitset> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll,ll> pll; typedef pair<int,int> pi; typedef pair<double,double> pd; typedef pair<double,ll> pdl; #define F first #define S second const ll E=1e18+7; const ll MOD=1000000007; int main(){ ll h,w,k; cin>>h>>w>>k; vector<string> A(h); for(int i=0;i<h;i++){cin>>A[i];} pll s; for(int i=0;i<h;i++){ for(int t=0;t<w;t++){ if(A[i][t]=='S'){s={i,t};} } } ll ans=E; queue<pll> Q; Q.push(s); vector<vector<ll>> dist(h,vector<ll>(w,E)); dist[s.F][s.S]=0; vector<pll> d={{0,1},{1,0},{-1,0},{0,-1}}; bool done=false; while(!Q.empty() && !done){ pll W=Q.front(); Q.pop(); if(dist[W.F][W.S]>=k){continue;} for(int i=0;i<4 && !done;i++){ pll k=W; k.F+=d[i].F; k.S+=d[i].S; if(A[k.F][k.S]=='#' || dist[k.F][k.S]!=E){continue;} dist[k.F][k.S]=dist[W.F][W.S]+1; Q.push({k.F,k.S}); if(k.F==0 || k.S==0 || k.F==h-1 || k.S==w-1){ ans=dist[k.F][k.S]; done=true; } } } for(int i=0;i<h;i++){ for(int t=0;t<w;t++){ if(dist[i][t]!=E){ ans=min(min(ans,k+i),min(k+t,w-1-t+k),min(h-1-i+k,ans)); } } } cout<<ans<<endl; return 0; }
In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/iomanip:42, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = long long int; _Compare = long long int]': a.cc:73:24: required from here 73 | ans=min(min(ans,k+i),min(k+t,w-1-t+k),min(h-1-i+k,ans)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:284:17: error: '__comp' cannot be used as a function 284 | if (__comp(__b, __a)) | ~~~~~~^~~~~~~~~~
s756464505
p03725
Java
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author prakharjain */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); agc014c solver = new agc014c(); solver.solve(1, in, out); out.close(); } static class agc014c { boolean[][] vis; int inf = 100000; int r; int c; public void solve(int testNumber, InputReader in, OutputWriter out) { r = in.nextInt(); c = in.nextInt(); int k = in.nextInt(); String[] a = new String[c]; int si = -1; int sj = -1; for (int i = 0; i < r; i++) { a[i] = in.next(); for (int j = 0; j < c; j++) { if (a[i].charAt(j) == 'S') { si = i; sj = j; } } } vis = new boolean[r][c]; dfs(si, sj, a, k); int ans = inf; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (vis[i][j]) { int mind = inf; mind = Math.min(mind, i); mind = Math.min(mind, j); mind = Math.min(mind, c - 1 - j); mind = Math.min(mind, r - 1 - i); int ca = (mind + k - 1) / k; ans = Math.min(ans, 1 + ca); } } } out.println(ans); } void dfs(int ri, int ci, String[] a, int cd) { if (vis[ri][ci]) return; if (a[ri].charAt(ci) == '#') return; vis[ri][ci] = true; if (cd == 0) return; if (ri > 0) dfs(ri - 1, ci, a, cd - 1); if (ci > 0) dfs(ri, ci - 1, a, cd - 1); if (ci < c - 1) dfs(ri, ci + 1, a, cd - 1); if (ri < r - 1) dfs(ri + 1, ci, a, cd - 1); } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void println(int i) { writer.println(i); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; }
Main.java:157: error: reached end of file while parsing } ^ 1 error
s177014469
p03725
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 #include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; const int M = 1e3; char mmp[M][M] , s[M][M]; int h , w , k , step[M][M] , dr[4][2] = {1 , 0 , -1 , 0 , 0 , 1 , 0 , -1}; struct TnT { int x , y , step , flag; }; bool vis[M][M]; void bfs(TnT sta) { memset(step , 0 , sizeof(step)); step[sta.x][sta.y] = 1; memset(vis , false , sizeof(vis)); vis[sta.x][sta.y] = true; queue<TnT>q; q.push(sta); while(!q.empty()) { TnT gg = q.front(); q.pop(); for(int i = 0 ; i < 4 ; i++) { TnT gl = gg; gl.x += dr[i][0]; gl.y += dr[i][1]; if(gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !vis[gl.x][gl.y]) { gl.step++; step[gl.x][gl.y] = gl.step; vis[gl.x][gl.y] = true; q.push(gl); } } } } int main() { scanf("%d%d%d" , &h , &w , &k); for(int i = 0 ; i < h ; i++) { scanf("%s" , mmp[i]); } TnT sta; for(int i = 0 ; i < h ; i++) { for(int j = 0 ; j < w ; j++) { if(mmp[i][j] == 'S') { sta.x = i , sta.y = j; break; } } } sta.step = 0 , sta.flag = k; bfs(sta); int ans = 1000000000; for(int i = 0 ; i < h ; i++) { for(int j = 0 ; j < w ; j++) { if(step[i][j] != 0) { if(i == 0 || i == h - 1 || j == 0 || j == w - 1) { int gg = step[i][j]; if(gg % k == 0) { ans = min(ans , gg / k); } else { ans = min(ans , gg / k + 1); } } else { int gg = step[i][j] , gl = 0; if(gg % k == 0) { gl = gg / k; } else { gl = gg / k + 1; } gg = i; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = j; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = h - 1 - i; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = w - 1 - j; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } } } } } printf("%d\n" , ans); return 0; }
a.cc:2:1: error: expected unqualified-id before numeric constant 2 | 1 | ^ In file included from /usr/include/c++/14/iosfwd:42, from /usr/include/c++/14/ios:40, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:109: /usr/include/c++/14/bits/postypes.h:68:11: error: 'ptrdiff_t' does not name a type 68 | typedef ptrdiff_t streamsize; // Signed integral type | ^~~~~~~~~ /usr/include/c++/14/bits/postypes.h:41:1: note: 'ptrdiff_t' is defined in header '<cstddef>'; this is probably fixable by adding '#include <cstddef>' 40 | #include <cwchar> // For mbstate_t +++ |+#include <cstddef> 41 | In file included from /usr/include/c++/14/bits/exception_ptr.h:38, from /usr/include/c++/14/exception:166, from /usr/include/c++/14/ios:41: /usr/include/c++/14/new:131:26: error: declaration of 'operator new' as non-function 131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~~~ /usr/include/c++/14/new:131:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 131 | _GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~ In file included from /usr/include/wchar.h:35, from /usr/include/c++/14/cwchar:44, from /usr/include/c++/14/bits/postypes.h:40: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:132:41: error: attributes after parenthesized initializer ignored [-fpermissive] 132 | __attribute__((__externally_visible__)); | ^ /usr/include/c++/14/new:133:26: error: declaration of 'operator new []' as non-function 133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~~~ /usr/include/c++/14/new:133:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 133 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:134:41: error: attributes after parenthesized initializer ignored [-fpermissive] 134 | __attribute__((__externally_visible__)); | ^ /usr/include/c++/14/new:140:29: error: 'std::size_t' has not been declared 140 | void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT | ^~~ /usr/include/c++/14/new:142:31: error: 'std::size_t' has not been declared 142 | void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT | ^~~ /usr/include/c++/14/new:145:26: error: declaration of 'operator new' as non-function 145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~~~~ /usr/include/c++/14/new:145:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:145:52: error: expected primary-expression before 'const' 145 | _GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~ /usr/include/c++/14/new:147:26: error: declaration of 'operator new []' as non-function 147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~~~~ /usr/include/c++/14/new:147:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:147:54: error: expected primary-expression before 'const' 147 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT | ^~~~~ /usr/include/c++/14/new:154:26: error: declaration of 'operator new' as non-function 154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) | ^~~~~~~~ /usr/include/c++/14/new:154:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:154:68: error: expected primary-expression before ')' token 154 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) | ^ /usr/include/c++/14/new:155:73: error: attributes after parenthesized initializer ignored [-fpermissive] 155 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); | ^ /usr/include/c++/14/new:156:26: error: declaration of 'operator new' as non-function 156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~~~~ /usr/include/c++/14/new:156:44: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:156:68: error: expected primary-expression before ',' token 156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) | ^ /usr/include/c++/14/new:156:70: error: expected primary-expression before 'const' 156 | _GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~ /usr/include/c++/14/new:162:26: error: declaration of 'operator new []' as non-function 162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) | ^~~~~~~~ /usr/include/c++/14/new:162:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:162:70: error: expected primary-expression before ')' token 162 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) | ^ /usr/include/c++/14/new:163:73: error: attributes after parenthesized initializer ignored [-fpermissive] 163 | __attribute__((__externally_visible__, __alloc_size__ (1), __malloc__)); | ^ /usr/include/c++/14/new:164:26: error: declaration of 'operator new []' as non-function 164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~~~~ /usr/include/c++/14/new:164:46: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:214:23: note: 'size_t' declared here 214 | typedef __SIZE_TYPE__ size_t; | ^~~~~~ /usr/include/c++/14/new:164:70: error: expected primary-expression before ',' token 164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) | ^ /usr/include/c++/14/new:164:72: error: expected primary-expression before 'const' 164 | _GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) | ^~~~~ /usr/include/c++/14/new:171:29: error: 'std::size_t' has not been declared 171 | void operator delete(void*, std::size_t, std::align_val_t) | ^~~ /usr/include/c++/14/new:173:31: error: 'std::size_t' has not been declared 173 | void operator delete[](void*, std::size_t, std::align_val_t) | ^~~ /usr/include/c++/14/new:179:33: error: declaration of 'operator new' as non-function 179 | _GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT | ^~~~~~~~ /usr/include/c++/14/new:179:51: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 179 | _GLIBCXX_NOD
s346540485
p03725
C++
#include<cstdio> #include<queue> #include<cstring> #include<algorithm> #define pii pair<int,int> #define mp make_pair using namespace std; int n,m,k,cx,cy,ans=1e9; char s[805][805]; int d[805][805]; const int dx[]={0,1,-1,0},dy[]={1,0,0,-1}; void bfs() { queue<pair<pii,int> > q; q.push(mp(pii(cx,cy),0)); while(!q.empty()) { int x=q.front().first.first,y=q.front().first.second,z=q.front().second;q.pop(); if(d[x][y]<=z||s[x][y]=='#')continue; d[x][y]=z; for(int i=0;i<4;i++) q.push(mp(pii(x+dx[i],y+dy[i]),z+1)); } } int main() { scanf("%d%d%d",&n,&m,&k);gets(s[0]); for(int i=0;i<n;i++) { gets(s[i]); for(int j=0;j<m;j++) {if(s[i][j]=='S')cx=i,cy=j,s[i][j]='.';d[i][j]=1e9;} } bfs(); for(int i=0;i<n;i++) for(int j=0;j<m;j++) if(d[i][j]<=k) ans=min(ans,1+(min(min(i,n-i-1),min(j,m-j-1))+k-1)/k); printf("%d\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:27:34: error: 'gets' was not declared in this scope; did you mean 'getw'? 27 | scanf("%d%d%d",&n,&m,&k);gets(s[0]); | ^~~~ | getw
s904180394
p03725
C++
#include<bits/stdc++.h> #include<queue> using namespace std; const int dx[]={1,0,-1,0};//position prepare const int dy[]={0,1,0,-1};//position prepare int n,m,k; int d[1050][1050];//record distance int sx,sy,x,y; int xx,yy; char c[1050][1050]; queue<pair<int,int> > q; bool check(int a,int b){//check if the grid is in use if(a>=0&&a<n&&b>=0&&b<m&&c[a][b]!='#'){ return true; } return false; } int minidis(int a,int b){ int cnt=a; cnt=min(min(b,n-1-a),m-1-b); return cnt; } /*void bfs(){//bfs while(!q.empty()){ x=q.front().first; y=q.front().second; q.pop(); for(int i=0;i<4;i++){//check distance xx=x+dx[i]; yy=y+dy[i]; if(check(xx,yy)&&d[xx][yy]<0){ d[xx][yy]=d[x][y]+1; q.push(make_pair(xx,yy)); } } } } */ int main(){ cin>>n>>m>>k; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>c[i][j]; if(c[i][j]=='S'){ sx=i; sy=j; } } } memset(d,-1,sizeof(d)); d[sx][sy]=0; q.push(make_pair(sx,sy)); while(!q.empty()){ x=q.front().first; y=q.front().second; q.pop(); for(int i=0;i<4;i++){//check distance xx=x+dx[i]; yy=y+dy[i]; if(check(xx,yy)&&d[xx][yy]<0){ d[xx][yy]=d[x][y]+1; q.push(make_pair(xx,yy)); } } } long long res=999999999; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(d[i][j]>=0&&d[i][j]<=k){ res=min(res,1+((minidis(i,j)+k-1)/k)); } } } cout<<res<<endl; return 0; }
a.cc: In function 'int main()': a.cc:70:40: error: no matching function for call to 'min(long long int&, int)' 70 | res=min(res,1+((minidis(i,j)+k-1)/k)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:70:40: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 70 | res=min(res,1+((minidis(i,j)+k-1)/k)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:70:40: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 70 | res=min(res,1+((minidis(i,j)+k-1)/k)); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s857482463
p03725
C++
#include <bits/stdc++.h> using std::cout; using std::endl; using std::cin; constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1}; int dp[h][w][801]; bool used[h][w]; int main(){ int h, w, K; cin >> h >> w >> K; std::vector<std::string> s(h); for(int i = 0; i < h; i++) cin >> s[i]; int sx, sy; for(int i = 0; i < h; i++){ for(int j = 0; j < w; j++){ if(s[i][j] != 'S') continue; sx = i; sy = j; i = j = 1e9; } } used[sx][sy] = true; typedef std::pair<int, std::pair<int, int>> P; std::queue<P> qu; qu.push({0, {sx, sy}}); for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) for(int k = 0; k < 801; k++) dp[i][j][k] = 1e9; dp[sx][sy][0] = 0; while(!qu.empty()){ auto p = qu.front(); qu.pop(); for(int i = 0; i < 4; i++){ int nx = p.second.first + vy[i], ny = p.second.second + vx[i]; if(nx<0||ny<0||nx>=h||ny>=w) continue; int block = (s[nx][ny] == '#'); if(dp[p.second.first][p.second.second][p.first] + 1 >= dp[nx][ny][p.first + block]) continue; dp[nx][ny][p.first + block] = dp[p.second.first][p.second.second][p.first] + 1; qu.push({p.first + block, {nx, ny}}); } } int mi = 1e9; for(int i = 0; i < w; i++){ for(int j = 1; j < 801; j++){ mi = std::min(mi, std::max(std::max(2, (dp[0][i][j] + K - 1) / K), j / K + 1)); mi = std::min(mi, std::max(std::max(2, (dp[i][0][j] + K - 1) / K), j / K + 1)); mi = std::min(mi, std::max(std::max(2, (dp[h - 1][i][j] + K - 1) / K), j / K + 1)); mi = std::min(mi, std::max(std::max(2, (dp[i][w - 1][j] + K - 1) / K), j / K + 1)); } mi = std::min(mi, (dp[0][i][0] + K - 1) / K); mi = std::min(mi, (dp[i][0][0] + K - 1) / K); mi = std::min(mi, (dp[h - 1][i][0] + K - 1) / K); mi = std::min(mi, (dp[i][w - 1][0] + K - 1) / K); } cout << mi << endl; return 0; }
a.cc:7:8: error: 'h' was not declared in this scope 7 | int dp[h][w][801]; | ^ a.cc:7:11: error: 'w' was not declared in this scope 7 | int dp[h][w][801]; | ^ a.cc:8:11: error: 'h' was not declared in this scope 8 | bool used[h][w]; | ^ a.cc:8:14: error: 'w' was not declared in this scope 8 | bool used[h][w]; | ^ a.cc: In function 'int main()': a.cc:24:9: error: 'used' was not declared in this scope 24 | used[sx][sy] = true; | ^~~~ a.cc:30:33: error: 'dp' was not declared in this scope; did you mean 'dup'? 30 | dp[i][j][k] = 1e9; | ^~ | dup a.cc:32:9: error: 'dp' was not declared in this scope; did you mean 'dup'? 32 | dp[sx][sy][0] = 0; | ^~ | dup
s882192813
p03725
C++
#include<iostream> #include<vector> #include<string> #include<set> #include<map> #include<algorithm> #include<queue> #include<list> #include<stack> #include<cstdio> #include<fstream> #include<numeric> #include<functional> #include<utility> #include<memory> #include <cstring> using namespace std; const int M = 1e3; char mmp[M][M] , s[M][M]; int h , w , k , step[M][M] , dr[4][2] = {1 , 0 , -1 , 0 , 0 , 1 , 0 , -1}; struct TnT { int x , y , step , flag; }; bool visit[M][M]; void bfs(TnT sta) { memset(step , 0 , sizeof(step)); step[sta.x][sta.y] = 1; memset(vis , false , sizeof(vis)); visit[sta.x][sta.y] = true; queue<TnT>q; q.push(sta); while(!q.empty()) { TnT gg = q.front(); q.pop(); for(int i = 0 ; i < 4 ; i++) { TnT gl = gg; gl.x += dr[i][0]; gl.y += dr[i][1]; if(gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !visit[gl.x][gl.y]) { gl.step++; step[gl.x][gl.y] = gl.step; visit[gl.x][gl.y] = true; q.push(gl); } } } } int main() { cin>>h>>w>>K; for(int i = 0 ; i < h ; i++) { cin>>mmp[i]; } TnT sta; for(int i = 0 ; i < h ; i++) { for(int j = 0 ; j < w ; j++) { if(mmp[i][j] == 'S') { sta.x = i , sta.y = j; break; } } } sta.step = 0 , sta.flag = k; bfs(sta); int ans = 1000000000; for(int i = 0 ; i < h ; i++) { for(int j = 0 ; j < w ; j++) { if(step[i][j] != 0) { if(i == 0 || i == h - 1 || j == 0 || j == w - 1) { int gg = step[i][j]; if(gg % k == 0) { ans = min(ans , gg / k); } else { ans = min(ans , gg / k + 1); } } else { int gg = step[i][j] , gl = 0; if(gg % k == 0) { gl = gg / k; } else { gl = gg / k + 1; } gg = i; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = j; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = h - 1 - i; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } gg = w - 1 - j; if(gg % k == 0) { ans = min(ans , gl + gg / k); } else { ans = min(ans , gl + gg / k + 1); } } } } } cout<<ans; return 0; }
a.cc: In function 'void bfs(TnT)': a.cc:28:12: error: 'vis' was not declared in this scope 28 | memset(vis , false , sizeof(vis)); | ^~~ a.cc: In function 'int main()': a.cc:49:16: error: 'K' was not declared in this scope 49 | cin>>h>>w>>K; | ^
s050566337
p03725
C++
#include <iostream> #include <queue> #include <tuple> #include <cstring> using namespace std; static int dr[4] = {1, 0, -1, 0}, dc[4] = {0, 1, 0, -1}; static int H, W, K; bool inside(int r, int c) { return 0 <= r and r < H and 0 <= c and c < W; } int main() { const int MAXH = 810; const int MAXW = 810; cin >> H >> W >> K; int sr = -1, sc = -1; string A[MAXH]; for (int r = 0; r < H; r++) { cin >> A[r]; for (int c = 0; c < W; c++) { if (A[r][c] == 'S') { sr = r; sc = c; } } } static int dist[MAXH][MAXW]; memset(dist, -1, sizeof(dist)); queue<tuple<int, int, int>> Q; dist[sr][sc] = 0; Q.push(make_tuple(sr, sc, 0)); int ans = W * H; while (!Q.empty()) { int r, c, d; tie(r, c, d) = Q.front(); Q.pop(); int x = min({r, H - 1 - r, c, W - 1 - c}); ans = min(ans, (x + K - 1) / K + 1); if (d == K) continue; for (int i = 0; i < 4; i++) { int nr = r + dr[i], nc = c + dc[i]; if (inside(nr, nc) and dist[nr][nc] < 0 and A[nr][nc] != '#') { dist[nr][nc] = d + 1; Q.push(make_tuple(nr, nc, d + 1)); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:47:20: error: no matching function for call to 'min(<brace-enclosed initializer list>)' 47 | int x = min({r, H - 1 - r, c, W - 1 - c}); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 1 provided
s032610600
p03725
C++
#include <iostream> #include <queue> #include <tuple> #include <cstring> using namespace std; static int dr[4] = {1, 0, -1, 0}, dc[4] = {0, 1, 0, -1}; static int H, W, K; bool inside(int r, int c) { return 0 <= r and r < H and 0 <= c and c < W; } int main() { const int MAXH = 810; const int MAXW = 810; cin >> H >> W >> K; int sr = -1, sc = -1; string A[MAXH]; for (int r = 0; r < H; r++) { cin >> A[r]; for (int c = 0; c < W; c++) { if (A[r][c] == 'S') { sr = r; sc = c; } } } static int dist[MAXH][MAXW]; memset(dist, -1, sizeof(dist)); queue<tuple<int, int, int>> Q; dist[sr][sc] = 0; Q.push({sr, sc, 0}); int ans = W * H; while (!Q.empty()) { int r, c, d; tie(r, c, d) = Q.front(); Q.pop(); int x = min({r, H - 1 - r, c, W - 1 - c}); ans = min(ans, (x + K - 1) / K + 1); if (d == K) continue; for (int i = 0; i < 4; i++) { int nr = r + dr[i], nc = c + dc[i]; if (inside(nr, nc) and dist[nr][nc] < 0 and A[nr][nc] != '#') { dist[nr][nc] = d + 1; Q.push({nr, nc, d + 1}); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:47:20: error: no matching function for call to 'min(<brace-enclosed initializer list>)' 47 | int x = min({r, H - 1 - r, c, W - 1 - c}); | ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 1 provided
s602290141
p03725
C++
#pragma GCC optimize("O3") #include<bits/stdc++.h> #define rc(x) return cout<<x<<endl,0 #define pb push_back #define in insert #define er erase #define fr first #define sc second typedef long long ll; const long long llinf=LLONG_MAX; const int inf=INT_MAX; const int nmax=1e5+5; const int mod=1e9+7; using namespace std; int n,m,k,i,j,l,r,viz[801][801]; ll ans=llinf; pair<ll,ll>a[]={{1,0},{-1,0},{0,1},{0,-1}}; char c[801][801]; void solve(int i,int j) { viz[i][j]=1; int d=min({i,j,n-i-1,m-j-1}); ans=min(ans,(d+k-1)/k); for(int t=0;t<4;t++)if(i+a[t].fr>=0 && i+a[t].fr<n && j+a[t].sc>=0 && j+a[t].sc<m && !viz[i+a[t].fr][j+a[t].sc] && c[i+a[t].fr][j+a[t].sc]!='#' && abs(l-i-a[t].fr)+abs(r-j-a[t].sc)<=k)solve(i+a[t].fr,j+a[t].sc); } int main() { //freopen("sol.in","r",stdin); ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); cin>>n>>m>>k; for(i=0;i<n;i++) for(j=0;j<m;j++) { cin>>c[i][j]; if(c[i][j]=='S')l=i,r=j; } solve(l,r); cout<<ans+1<<endl; return 0; }
a.cc: In function 'void solve(int, int)': a.cc:23:16: error: no matching function for call to 'min(ll&, int)' 23 | ans=min(ans,(d+k-1)/k); | ~~~^~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:2: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: template argument deduction/substitution failed: a.cc:23:16: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int') 23 | ans=min(ans,(d+k-1)/k); | ~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:61: /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)' 5686 | min(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate expects 1 argument, 2 provided /usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)' 5696 | min(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5696:5: note: template argument deduction/substitution failed: a.cc:23:16: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 23 | ans=min(ans,(d+k-1)/k); | ~~~^~~~~~~~~~~~~~~
s584372064
p03725
C++
#include<bits/stdc++.h> using namespace std; int H, W, K; int MAP[1000][1000]; int x, y, vis[1000][1000]; int ans = 2147483647; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; struct PR { int x, y, now; PR() {x = y = now = 0;} PR(int _x, int _y, int _now) {x = _x, y = _y, now = _now;} }; bool check(int x, int y) { if (x < 0 || x > H) return 0; if (y < 0 || y > W) return 0; if (MAP[x][y]) return 0; return 1; } int main() { cin >> H >> W >> K; for (int i = 1; i <= H; i ++) { string s; cin >> s; for (int j = 1; j <= W; j ++) { if (s[j - 1] == '#') MAP[i][j] = 1; else { MAP[i][j] = 0; if (s[j - 1] == 'S') x = i, y = j; } } } queue<PR> Q; Q.push((PR){x, y, 0}); while (!Q.empty()) { PR tmp = Q.front(); Q.pop(); if (tmp.now > K) continue; if (vis[tmp.x][tmp.y] <= tmp.now && vis[tmp.x][tmp.y] != 0) continue; vis[tmp.x][tmp.y] = tmp.now; int num = min(min(H - tmp.x, W - tmp.y), min(tmp.x - 1, tmp.y - 1)); tmp = (tmp + K - 1) / K; if (tmp + 1 > ans) continue; ans = min(ans, tmp + 1); for (int i = 0; i < 4; i ++) { if (check(tmp.x + dx[i], tmp.y + dy[i])) Q.push((PR){tmp.x + dx[i], tmp.y + dy[i], tmp.now + 1}); } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:40:28: error: no match for 'operator+' (operand types are 'PR' and 'int') 40 | tmp = (tmp + K - 1) / K; | ~~~ ^ ~ | | | | PR int In file included from /usr/include/c++/14/bits/stl_algobase.h:67, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)' 627 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:627:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'int' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)' 1798 | operator+(typename move_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1798:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'const std::move_iterator<_IteratorL>' and 'int' 40 | tmp = (tmp + K - 1) / K; | ^ In file included from /usr/include/c++/14/string:54, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3598 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3598:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3616 | operator+(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3616:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'const _CharT*' and 'PR' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3635 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3635:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)' 3652 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3652:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3670:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, _CharT)' 3670 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3670:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3682:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3682 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3682:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3689:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)' 3689 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3689:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3696:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)' 3696 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3696:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3719:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)' 3719 | operator+(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3719:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'const _CharT*' and 'PR' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3726:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, __cxx11::basic_string<_CharT, _Traits, _Allocator>&&)' 3726 | operator+(_CharT __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3726:5: note: template argument deduction/substitution failed: a.cc:40:30: note: mismatched types 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'int' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3733:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, const _CharT*)' 3733 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3733:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ /usr/include/c++/14/bits/basic_string.h:3740:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(__cxx11::basic_string<_CharT, _Traits, _Allocator>&&, _CharT)' 3740 | operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3740:5: note: template argument deduction/substitution failed: a.cc:40:30: note: 'PR' is not derived from 'std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | tmp = (tmp + K - 1) / K; | ^ In file included from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127: /usr/include/c++/14/complex:340:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator+(const complex<_Tp>&, const complex<_Tp>&)' 340 | operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:340:5: note: template argument deduction/substitution failed: a.cc:40:30: note:
s419866929
p03725
C++
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include <cmath> #include <algorithm> #include <cstdlib> #include <utility> #include <map> #include <stack> #include <set> #include <vector> #include <queue> #include <deque> #include <sstream> #include <bitset> #define x first #define y second #define mp make_pair #define pb push_back #define LL long long #define ld long double #define Pair pair<int,int> #define LOWBIT(x) x & (-x) using namespace std; const int INF=0x7ffffff; int ans=INF; int move[5][3]; bool visited[848][848]; int r,c,k; int sx,sy; int a[848][848]; string s; void dfs(int x,int y,int step) { int cur_ans=x-1; cur_ans=min(cur_ans,y-1); cur_ans=min(cur_ans,r-x); cur_ans=min(cur_ans,c-y); ans=min(ans,cur_ans); visited[x][y]=true; if (step==k) return; int xx,yy,i; for (i=1;i<=4;i++) { xx=x+move[i][1];yy=y+move[i][2]; if (xx<1 || xx>r || yy<1 || yy>c) continue; if (a[xx][yy]==1 || visited[xx][yy]) continue; dfs(xx,yy,step+1); } } int main () { ios::sync_with_stdio(false); int i,j; move[1][1]=1;move[1][2]=0; move[2][1]=0;move[2][2]=1; move[3][1]=-1;move[3][2]=0; move[4][1]=0;move[4][2]=-1; cin>>r>>c>>k; for (i=1;i<=r;i++) { cin>>s; for (j=1;j<=c;j++) { if (s[j-1]=='#') a[i][j]=1; if (s[j-1]=='.') a[i][j]=2; if (s[j-1]=='S') { sx=i;sy=j; a[i][j]=2; } } } dfs(sx,sy,0); int fans=1+(ans+k-1)/k; cout<<fans<<endl; return 0; } /* 3 3 3 #.# #S. ### 3 3 3 ### #S# ### 7 7 2 ####### ####### ##...## ###S### ##.#.## ###.### ####### */
a.cc: In function 'void dfs(int, int, int)': a.cc:49:22: error: reference to 'move' is ambiguous 49 | xx=x+move[i][1];yy=y+move[i][2]; | ^~~~ In file included from /usr/include/c++/14/algorithm:86, from a.cc:6: /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:2: /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ In file included from /usr/include/c++/14/bits/exception_ptr.h:41, from /usr/include/c++/14/exception:166, from /usr/include/c++/14/ios:41: /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:49:38: error: reference to 'move' is ambiguous 49 | xx=x+move[i][1];yy=y+move[i][2]; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc: In function 'int main()': a.cc:60:9: error: reference to 'move' is ambiguous 60 | move[1][1]=1;move[1][2]=0; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:60:22: error: reference to 'move' is ambiguous 60 | move[1][1]=1;move[1][2]=0; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:61:9: error: reference to 'move' is ambiguous 61 | move[2][1]=0;move[2][2]=1; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:61:22: error: reference to 'move' is ambiguous 61 | move[2][1]=0;move[2][2]=1; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:62:9: error: reference to 'move' is ambiguous 62 | move[3][1]=-1;move[3][2]=0; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:62:23: error: reference to 'move' is ambiguous 62 | move[3][1]=-1;move[3][2]=0; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:30:5: note: 'int move [5][3]' 30 | int move[5][3]; | ^~~~ a.cc:63:9: error: reference to 'move' is ambiguous 63 | move[4][1]=0;move[4][2]=-1; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_I
s953950416
p03725
C++
#include<iostream> #include<fstream> #include<stdio.h> #include<string> #include<vector> #include<map> #include<math.h> #include<algorithm> #include<iomanip> #include<set> using namespace std; class Node { public: int x, y, d; Node(int a, int b, int c) { x = a; y = b; d = c; } }; bool operator>(const Node &lhs, const Node &rhs) { return lhs.d > rhs.d; } bool operator<(const Node &lhs, const Node &rhs) { return lhs.d < rhs.d; } int f(int x, int y, int w, int h, int k) { int ww = ((x) > (w - x - 1)) ? (w - x - 1) : (x); int hh =((y) > (h - y - 1)) ? (h - y - 1) : (y); ww = (ww + k - 1)/k; hh = (hh + k - 1)/k; return (ww > hh) ? hh : ww; } int main() { int hx[4] = {0, 0, 1, -1}; int hy[4] = {-1, 1, 0, 0}; vector<string> s; int w, h, k; cin >> h >> w >> k; s.resize(h); for(int i = 0; i < h; i++) { cin >> s[i]; } int x, y; for (int i = 0; i < h; i++) { for(int j = 0; j < w; j++) { if(s[i][j] == 'S') { s[i][j] = '#'; x = j; y = i; } } } multiset<Node> q; Node node(x, y, 1); int ans = f(x, y, w, h, k) + 1; q.insert(node); while(q.size() > 0) { Node now = *q.begin(); q.erase(q.begin()); if(now.x < 0 || now.x >= w || now.y < 0 || now.y >= h) { ans = 0; break; } if(f(now.x, now.y, w, h, k) + 1 < ans) { ans = f(now.x, now.y, w, h, k) + 1; } if(now.d - 1 == k) { continue; } for(int i = 0; i < 4; i++) { if(s[now.y + hy[i]][now.x + hx[i]] == '.') { if(now.x + hx[i] == 0 || now.x + hx[i] == w - 1 || now.y + hy[i] == 0 || now.y + hy[i] == h - 1) { ans = 1; continue; } s[now.y + hy[i]][now.x + hx[i]] = '#'; Node next(now.x + hx[i], now.y + hy[i], now.d + 1); q.insert(next); } } } cout << ans << endl; return 0; }
a.cc:86:16: error: extended character   is not valid in an identifier 86 | if(now.d - 1 == k) { | ^ a.cc:86:20: error: extended character   is not valid in an identifier 86 | if(now.d - 1 == k) { | ^ a.cc: In function 'int main()': a.cc:86:16: error: 'class Node' has no member named 'd\U00003000' 86 | if(now.d - 1 == k) { | ^~~ a.cc:86:20: error: '\U000030001' was not declared in this scope 86 | if(now.d - 1 == k) { | ^~~
s327826809
p03725
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <int, pii> piii; #define fr first #define sc second #define pb push_back #define mpr make_pair #define ppb pop_back() #define ins insert #define sz(s) int(s.size()) #define all(x) x.begin(), x.end() #define lb lower_bound #define ub upper_bound int n, m, k, d[1000][1000], b[1000][1000]; bool in(int x, int y){ if(x < 1 || x > n || y < 1 || y > m)return 0; return 1; } pii s; set <piii> st; char c; int main() { ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> k; for(int i = 1;i <= n; ++ i){ for(int j = 1;j <= m; ++ j){ cin >> c; if(i == 1 || j == 1 || i == n || j == m){ d[i][j] = (c == '#'); st.ins(mpr(d[i][j], mpr(i, j))); } else { b[i][j] = 1; b[i][j] += (c == '#'); if(c == 'S')s = mpr(i, j); d[i][j] = 1000; } } } while(sz(st)){ piii p2 = *st.begin(); pii p = p2.sc; st.erase(st.begin()); for(int i = -1;i <= 1; ++ i){ for(int j = -1;j <= 1; ++ j){ if(abs(i + j) != 1)continue; if(!in(p.fr + i, p.sc + j))continue; if(d[p.fr + i][p.sc + j] > d[p.fr][p.sc] + b[p.fr + i][p.sc + j]){ st.erase(mpr(d[p.fr + i][p.sc + j], mpr(p.fr + i, p.sc + j))); d[p.fr + i][p.sc + j] = d[p.fr][p.sc] + b[p.fr + i][p.sc + j]; st.ins(mpr(d[p.fr + i][p.sc + j], mpr(p.fr + i, p.sc + j))); } } } } if(d[s.fr][s.sc] > 2 * k){ cout << k return 0; } cout << d[s.fr][s.sc]; return 0; }
a.cc: In function 'int main()': a.cc:65:26: error: expected ';' before 'return' 65 | cout << k | ^ | ; 66 | return 0; | ~~~~~~
s968185080
p03725
C++
#include<cstdio> #include<utility> #include<queue> #define N 800 using namespace std; int a[N+2][N+2]; char s[N+1]; queue<pair<int,int> > Q; int minim(int a,int b){ return (a<b) ? a : b; } int main(){ int n,m,k; int i,j; scanf ("%d%d%d\n",&n,&m,&k); pair<int,int> S; for(i=1;i<=n;i++){ gets(s); for(j=0;j<m;j++){ if (s[j]=='S') S={i,j+1}; else if (s[j]=='#') a[i][j+1]=-1; } } for(i=1;i<=n;i++) a[i][0]=a[i][m+1]=-1; for(j=1;j<=m;j++) a[0][j]=a[n+1][j]=-1; a[S.first][S.second]=1; Q.push({S.first,S.second}); int min=n; while(!Q.empty()){ S=Q.front(); Q.pop(); min=minim(min,minim(S.first-1,minim(S.second-1,minim(n-S.first,m-S.second)))); if (a[S.first][S.second]<=k){ if (a[S.first+1][S.second]==0){ a[S.first+1][S.second]=a[S.first][S.second]+1; Q.push({S.first+1,S.second}); } if (a[S.first-1][S.second]==0){ a[S.first-1][S.second]=a[S.first][S.second]+1; Q.push({S.first-1,S.second}); } if (a[S.first][S.second+1]==0){ a[S.first][S.second+1]=a[S.first][S.second]+1; Q.push({S.first,S.second+1}); } if (a[S.first][S.second-1]==0){ a[S.first][S.second-1]=a[S.first][S.second]+1; Q.push({S.first,S.second-1}); } } } printf ("%d",1+(min-1)/k+1); return 0; }
a.cc: In function 'int main()': a.cc:24:9: error: 'gets' was not declared in this scope; did you mean 'getw'? 24 | gets(s); | ^~~~ | getw
s582250066
p03725
C++
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<cmath> #include<algorithm> using namespace std; inline void write(int a){ if(a>=10)write(a/10); putchar('0'+a%10); } inline void writeln(int a){ write(a); puts(""); } inline int read()//不管是正负数,都可以 { int x = 0; char ch = getchar(); bool positive = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') positive = 0; for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return positive ? x : -x; } int ans=10000000,n,m,k,S1[4]={0,0,1,-1},S2[4]={1,-1,0,0},s1,s2; bool vis[1000][1000]; char ch[1000][1000]; inline void dfs(int x,int y,int zs){ if(vis[x][y]||ch[x][y]=='#')return; vis[x][y]=true; if(x==1||x==n||y==1||y==m){ ans=min(ans,1); return; } ans=min(ans,1+min((x-2)/k+1,min((y-2)/k+1,min((n-x-1)/k+1,(m-y-1)/k+1)))); if(zs<k)for(int i=0;i<4;i++)dfs(x+S1[i],y+S2[i],zs+1); } int main(){ int size = 25 << 20; // 256MB char *p = (char*)malloc(size) + size; __asm__("movl %0, %%esp\n" :: "r"(p)); n=read(); m=read(); k=read(); for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++)scanf("\n%c",&ch[i][j]); for(int j=1;j<=m;j++)if(ch[i][j]=='S'){ s1=i; s2=j; } } dfs(s1,s2,0); writeln(ans); }
a.cc: Assembler messages: a.cc:40: Error: operand type mismatch for `mov'
s651679842
p03725
C++
import java.io.*; import java.math.*; import java.util.*; public class Main { private static boolean debug = false; private static boolean elapsed = false; private static PrintWriter _out = new PrintWriter(System.out); private static PrintWriter _err = new PrintWriter(System.err); private int H; private int W; private int K; private int[][] b; private void solve(Scanner sc) { H = sc.nextInt(); W = sc.nextInt(); K = sc.nextInt(); sc.nextLine(); int x = -1; int y = -1; b = new int[H][W]; for (int i = 0; i < H; ++i) { String s = sc.nextLine(); for (int j = 0; j < W; ++j) { char ch = s.charAt(j); if (ch == '.') { b[i][j] = 1; } else if (ch == 'S') { b[i][j] = 2; x = j; y = i; } else { b[i][j] = -1; } } } int[][] m = { { 1, 0, }, { -1, 0, }, { 0, 1, }, { 0, -1, }, }; int[][] v = new int[H][W]; for (int i = 0; i < v.length; ++i) { Arrays.fill(v[i], -1); } v[y][x] = 0; Deque<Point> queue = new ArrayDeque<>(); queue.offer(new Point(x, y)); while (!queue.isEmpty()) { Point p = queue.poll(); for (int i = 0; i < m.length; ++i) { int xx = (int)(p.x + m[i][0]); int yy = (int)(p.y + m[i][1]); if (inBound(xx, yy) && b[yy][xx] >= 0 && v[yy][xx] < 0 && v[(int)p.y][(int)p.x] + 1 <= K) { v[yy][xx] = v[(int)p.y][(int)p.x] + 1; queue.offer(new Point(xx, yy)); } } } int rmin = Integer.MAX_VALUE; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (v[i][j] >= 0) { int minStep = Math.min(Math.min(j, W - j - 1), Math.min(i, H - i - 1)); rmin = Math.min(rmin, (minStep + K - 1) / K + 1); } } } _out.println(rmin); } private boolean inBound(int x, int y) { if (x >= 0 && y >= 0 && x < W && y < H) { return true; } else { return false; } } private static BigInteger C(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } for (long i = r; i > 1; --i) { res = res.divide(BigInteger.valueOf(i)); } return res; } private static BigInteger P(long n, long r) { BigInteger res = BigInteger.ONE; for (long i = n; i > n - r; --i) { res = res.multiply(BigInteger.valueOf(i)); } return res; } private static class Point implements Comparable<Point> { long x; long y; public Point(long x, long y) { this.x = x; this.y = y; } public boolean equals(Object o) { if (o instanceof Point) { Point that = (Point)o; return this.x == that.x && this.y == that.y; } return false; } public int hashCode() { int hashCode = 17; hashCode = hashCode * 31 + (int)(x ^ (x >>> 32)); hashCode = hashCode * 31 + (int)(y ^ (y >>> 32)); return hashCode; } public int compareTo(Point that) { if (this.x != that.x) { return this.x > that.x ? 1 : -1; } if (this.y != that.y) { return this.y > that.y ? 1 : -1; } return 0; } public String toString() { return "(" + x + ", " + y + ")"; } } /* * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9 * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18 */ public static void main(String[] args) { long S = System.currentTimeMillis(); Scanner sc = new Scanner(System.in); new Main().solve(sc); _out.flush(); long G = System.currentTimeMillis(); if (elapsed) { _err.println((G - S) + "ms"); } _err.flush(); } }
a.cc:1:1: error: 'import' does not name a type 1 | import java.io.*; | ^~~~~~ a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:2:1: error: 'import' does not name a type 2 | import java.math.*; | ^~~~~~ a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:3:1: error: 'import' does not name a type 3 | import java.util.*; | ^~~~~~ a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts' a.cc:5:1: error: expected unqualified-id before 'public' 5 | public class Main { | ^~~~~~
s346426509
p03725
C++
#include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <array> #include <deque> #include <algorithm> #include <utility> #include <cstdint> #include <functional> #include <iomanip> #include <numeric> #include <assert.h> auto& in = std::cin; auto& out = std::cout; int32_t H,W,K; char map[1000][1000]; bool ok[1000][1000]; int d[1000][1000]; // 最短距離 void func(int h, int w, int k) { if (h < 0 || H <= h || w < 0 || W <= w) { return; } if (k < 0) { return; } //if (ok[h][w]) { return; } if(d[h][w] <= K - k) return; if (map[h][w] == '#') { return; } ok[h][w] = true; d[h][w] = K - k; func(h - 1, w, k - 1); func(h + 1, w, k - 1); func(h, w - 1, k - 1); func(h, w + 1, k - 1); } int main() { using std::endl; in.sync_with_stdio(false); out.sync_with_stdio(false); in >> H>>W>>K; for (size_t i = 0; i < H; i++) { in >> map[i]; } int sx, sy; for (size_t i = 0; i < H; i++) { for (size_t w = 0; w < W; w++) { if (map[i][w] == 'S') { sx = w; sy = i; map[i][w] = '.'; } } } for(int i = 0; i < 1000; ++i){ d[i][j] = 999999; } func(sy, sx, K); int res = H*W; for (int i = 0; i < H; i++) { for (int w = 0; w < W; w++) { if (map[i][w] != '#' && ok[i][w]) { res = std::min(res, 1 + (std::min({ i,H - i - 1,w,W - w - 1 })+K-1)/K); } } } std::cout << res << std::endl; return 0; }
a.cc: In function 'int main()': a.cc:65:14: error: 'j' was not declared in this scope 65 | d[i][j] = 999999; | ^
s684700004
p03725
C++
#if 1 #include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <array> #include <deque> #include <algorithm> #include <utility> #include <cstdint> #include <functional> #include <iomanip> #include <numeric> #include <assert.h> auto& in = std::cin; auto& out = std::cout; int32_t H,W,K; char map[1000][1000]; bool ok[1000][1000]; void func(int h, int w, int k) { if (h < 0 || H <= h || w < 0 || W <= w) { return; } if (k < 0) { return; } if (ok[h][w]) { return; } if (map[h][w] == '#') { return; } ok[h][w] = true; func(h - 1, w, k - 1); func(h + 1, w, k - 1); func(h, w - 1, k - 1); func(h, w + 1, k - 1); } int main() { using std::endl; in.sync_with_stdio(false); out.sync_with_stdio(false); in >> H>>W>>K; for (size_t i = 0; i < H; i++) { in >> map[i]; } int sx, sy; for (size_t i = 0; i < H; i++) { for (size_t w = 0; w < W; w++) { if (map[i][w] == 'S') { sx = w; sy = i; map[i][w] = '.'; } } } func(sy, sx, K); int res = H*W; for (int i = 0; i < H; i++) { for (int w = 0; w < W; w++) { if (map[i][w] != '#' && ok[i][w]) { res = std::min(res, (long long)(1 + ceil(1.0 * (std::min({ i,H - i - 1,w,W - w - 1 }) / K))); } } } std::cout << res << std::endl; return 0; } #endif
a.cc: In function 'int main()': a.cc:70:69: error: 'ceil' was not declared in this scope 70 | res = std::min(res, (long long)(1 + ceil(1.0 * (std::min({ i,H - i - 1,w,W - w - 1 }) / K))); | ^~~~
s658853924
p03725
C++
#if 1 #include <iostream> #include <fstream> #include <string> #include <vector> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <queue> #include <stack> #include <array> #include <deque> #include <algorithm> #include <utility> #include <cstdint> #include <functional> #include <iomanip> #include <numeric> #include <assert.h> auto& in = std::cin; auto& out = std::cout; int32_t H,W,K; char map[1000][1000]; bool ok[1000][1000]; void func(int h, int w, int k) { if (h < 0 || H <= h || w < 0 || W <= w) { return; } if (k == 0) { return; } if (ok[h][w]) { return; } if (map[h][w] == '#') { return; } ok[h][w] = true; func(h - 1, w, k - 1); func(h + 1, w, k - 1); func(h, w - 1, k - 1); func(h, w + 1, k - 1); } int main() { using std::endl; in.sync_with_stdio(false); out.sync_with_stdio(false); in >> H>>W>>K; for (size_t i = 0; i < H; i++) { in >> map[i]; } int sx, sy; for (size_t i = 0; i < H; i++) { for (size_t w = 0; w < W; w++) { if (map[i][w] == 'S') { sx = w; sy = i; map[i][w] = '.'; } } } func(sy, sx, K); int res = H*W; for (int i = 0; i < H; i++) { for (int w = 0; w < W; w++) { if (map[i][w] != '#' && ok[i][w]) { res = std::min(res, 1 + (std::min({ i,H - i - 1,w,W - w - 1 })+K-1)/K); } } } std::cout << res << std::endl; return 0; }
a.cc:1: error: unterminated #if 1 | #if 1
s817615268
p03725
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<pair<int, int> > vp; #define pb push_back #define rep(i, a, n) for(int i = (a); i < (n); i++) #define dep(i, a, n) for(int i = (a); i >= (n); i--) #define out(n) cout << (n) << endl; __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int h, w, k, minw, mini, z; vector<vector<char> > buil(801, vector<char>(801)); vvi ma(801, vi(801, 99999)); int tansaku(int gh, int gw, int num) { int mmini = min(min(gh, h - gh), min(gw, w - gw)); if(ma[gh][gw] <= num || buil[gh][gw] == '#' || mini + (k - num) < mmini) { return 1; } if(gh == 0 || gh == h - 1 || gw == 0 || gw == w - 1) { return 0; } if(num == k) { int mh = min(gh, h - gh), mw = min(gw, w - gw); int res = min(mh, mw); if(mini > res) { mini = res; z = gh <= mw && gh <= h - gh ? 0 : h - gh <= mw && h - gh <= gh ? 1 : gw <= mh && gw <= w - gw ? 2 : 3; } return 1; } ma[gh][gw] = num; return min( min(tansaku(gh + 1, gw, num + 1), tansaku(gh - 1, gw, num + 1)), min(tansaku(gh, gw + 1, num + 1), tansaku(gh, gw - 1, num + 1)) ); } int main() { cin >> h >> w >> k; char a; int sh, sw; rep(i, 0, h) { rep(j, 0, w) { cin >> a; if(a == 'S') { sh = i; sw = j; } buil[i][j] = a; } } int mh = min(sh, h - sh), mw = min(sw, w - sw); mini = min(mh, mw); z = sh <= mw && sh <= h - sh ? 0 : h - sh <= sw && h - sh <= sh ? 1 : sw <= sh && sw <= w - sw ? 2 : 3; if(!tansaku(sh, sw, 0)) { out(1); return 0; } out((z == 0 ? mini : ) / k + 2) out(mini / k + 2); }
a.cc: In function 'int main()': a.cc:87:24: error: expected primary-expression before ')' token 87 | out((z == 0 ? mini : ) / k + 2) | ^ a.cc:13:25: note: in definition of macro 'out' 13 | #define out(n) cout << (n) << endl; | ^
s094218096
p03725
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<pair<int, int> > vp; #define pb push_back #define rep(i, a, n) for(int i = (a); i < (n); i++) #define dep(i, a, n) for(int i = (a); i >= (n); i--) #define out(n) cout << (n) << endl; __attribute__((constructor)) void initial() { cin.tie(0); ios::sync_with_stdio(false); } int h, w, k, minw, mini; vector<vector<char> > buil(801, vector<char>(801)); vvi ma(801, vi(801, 99999)); int tansaku(int gh, int gw, int num) { int mmini = min(min(gh, h - gh), min(gw, w - gw)); if(ma[gh][gw] <= num || buil[gh][gw] == '#' || mini + (k - num) < mmini) { return 1; } if(gh == 0 || gh == h - 1 || gw == 0 || gw == w - 1) { return 0; } if(num == k) { int res = min(min(gh, h - gh), min(gw, w - gw)); if(mini > res) { mini = res; } return 1; } ma[gh][gw] = num; return min( min(tansaku(gh + 1, gw, num + 1), tansaku(gh - 1, gw, num + 1)), min(tansaku(gh, gw + 1, num + 1), tansaku(gh, gw - 1, num + 1)) ); } int main() { cin >> h >> w >> k; char a; int sh, sw; rep(i, 0, h) { rep(j, 0, w) { cin >> a; if(a == 'S') { sh = i; sw = j; } buil[i][j] = a; } } mini = min(min(sh, h - sh), min(sw, w - sw)) if(!tansaku(sh, sw, 0)) { out(1); return 0; } out(min(min(h - mini, w - mini), mini) / k + 2); }
a.cc: In function 'int main()': a.cc:71:47: error: expected ';' before 'if' 71 | mini = min(min(sh, h - sh), min(sw, w - sw)) | ^ | ; 72 | 73 | if(!tansaku(sh, sw, 0)) { | ~~
s429110843
p03725
C++
#include <iostream> #include <sstream> #include <vector> #include <cmath> #include <ctime> #include <cassert> #include <ctype.h> #include <iomanip> #include <cstdio> #include <float.h> #include <queue> #include <set> #include <map> #include <fstream> #include <cstdlib> #include <string> #include <cstring> #include <algorithm> #include <numeric> #include <stack> #include <functional> // #include <pair> using namespace std; #define endl '\n' #define MOD 1000000007 #define INF 1ll<<30 // #define MAX 100010 #define eps 1e-11 #define bit_max 1ll<<32 #define _USE_MATH_DEFINES // long long binpow(long long a,long long b) // { // if (b == 1) return a; // long long res = binpow(a, b/2)%MOD; // if (b % 2) return (res*((res*a)%MOD))%MOD; // else return (res * res)%MOD; // } // long long int fact(long long int a) // { // if(a==0||a==1) // return 1; // long long int ans = 1; // for(int i=a;i>=1;i--) // ans = (ans * i); // return ans; // } // long long int ivmod(long long int a) // { // return binpow(a,MOD-2); // } // long long int ncr(long long int a,long long int b) // { // long long int pans=1; // for(int i =a;i>max(b,a-b);i--) // pans=pans*i; // long long int div = fact(min(b,a-b)); // // cout<<ans<<" "<<div<<endl; // pans = pans/div; // return pans; // } int h,w,k; char grid[1000][1000]; int dx[] = {1,0,0,-1}; int dy[] = {0,1,-1,0}; long long int cost[1000][1000]; long long int calc(int x,int y) { int mn; mn = min(x,y); mn = min(mn,h-1-x); mn = min(mn,w-1-y); // return mn; // } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif for(int i=0;i<1000;i++) { for(int j=0;j<1000;j++) cost[i][j] = 1e18; } long long int ans = 1e18; queue<int> q; cin>>h>>w>>k; int startx=-1,starty=-1; for(int i=0;i<h;i++) { for(int j=0;j<w;j++) { cin>>grid[i][j]; if(grid[i][j]=='S') { grid[i][j]='.'; startx = i; starty = j; } } } cost[startx][starty] = 0; q.push(startx); q.push(starty); ans = min(ans,calc(startx,starty)); int tx,ty; while(!q.empty()) { tx = q.front(); q.pop(); ty = q.front(); q.pop(); for(int i=0;i<4;i++) { int tdx,tdy; tdx = tx + dx[i]; tdy = ty + dy[i]; if(tdx < 0 || tdy<0 || tdx >= h ||tdy>=w) { continue; } if(grid[tdx][tdy]=='#') { continue; } if(cost[tdx][tdy]!=1e19) { continue; } cost[tdx][tdy] = cost[tx][ty] + 1; if(cost[tdx][tdy]==k) continue; q.push(tdx); q.push(tdy); } } cout<<ans+1<<endl; return 0; }
a.cc: In function 'long long int calc(int, int)': a.cc:83:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 83 | int main() | ^~ a.cc:83:9: note: remove parentheses to default-initialize a variable 83 | int main() | ^~ | -- a.cc:83:9: note: or replace parentheses with braces to value-initialize a variable a.cc:84:1: error: a function-definition is not allowed here before '{' token 84 | { | ^ a.cc:152:2: error: expected '}' at end of input 152 | } | ^ a.cc:75:1: note: to match this '{' 75 | { | ^ a.cc:152:2: warning: no return statement in function returning non-void [-Wreturn-type] 152 | } | ^
s854149278
p03725
C++
#include <iostream> #include <algorithm> #include <string.h> #include <vector> #include <queue> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define ull unsigned ll #define db double #define INF 0x3f3f3f3f #define MOD 1000000007 #define PII pair<int, int> const int N=805; int h,w,k; char grid[N][N]; bool vis[N][N]; bool lock_h(int l,int r,int x) { for (int i=l;i<=r;i++) { if (grid[x][i]=='#') return true; } return false; } bool lock_v(int u,int d,int y) { for (int i=u;i<=d;i++) { if (grid[i][y]=='#') return true; } return false; } int foo(int x,int y) { if (x==0||x==h-1||y==0||y==w-1) return 0; int res=INF; int tmp=(x-1)/k+1; if (lock_v(x-(((x-1)%k)+1),x-1,y)) tmp++; res=min(res,tmp); int xx=h-1-x; tmp=(xx-1)/k+1; if (lock_v(x+1,x+((xx-1)%k)+1,y)) tmp++; res=min(res,tmp); tmp=(y-1)/k+1; if (lock_h(y-(((y-1)%k)+1),y-1,x)) tmp++; res=min(res,tmp); int yy=w-1-y; tmp=(yy-1)/k+1; if (lock_h(y+1,y+((yy-1)%k)+1,x)) tmp++; res=min(res,tmp); return res; } int ans=INF; struct node { int x,y,dis; }; void bfs(int x,int y,int dis) { vis[x][y]=true; ans=min(ans,foo(x,y)); queue<node> q; q.push({x,y,0}); while (!q.empty()) { node cur=q.front(); q.pop(); if (vis[cur.xx][cur.yy]) continue; vis[cur.xx][cur.yy]=1; if (cur.dis>0) ans=min(ans,foo(cur.x,cur.y)); for (int i=-1;i<=1;i++) { for (int j=-1;j<=1;j++) { if ((i==0&&j==0)||(i!=0&&j!=0)) continue; int xx=x+i; int yy=y+j; if (xx>0&&xx<h&&yy>0&&yy<h&&!vis[xx][yy]&&grid[xx][yy]!='#'&&cur.dis<dis) { q.push({xx,yy,cur.dis+1}); } } } } } int main() { scanf("%d%d%d",&h,&w,&k); for (int i=0;i<h;i++) { scanf("%s",grid[i]); } int sx,sy; for (int i=0;i<h;i++) { for (int j=0;j<w;j++) { if (grid[i][j]=='S') { sx=i; sy=j; break; } } } bfs(sx,sy,0); printf("%d\n",ans); }
a.cc: In function 'void bfs(int, int, int)': a.cc:77:21: error: 'struct node' has no member named 'xx'; did you mean 'x'? 77 | if (vis[cur.xx][cur.yy]) continue; | ^~ | x a.cc:77:29: error: 'struct node' has no member named 'yy'; did you mean 'y'? 77 | if (vis[cur.xx][cur.yy]) continue; | ^~ | y a.cc:78:17: error: 'struct node' has no member named 'xx'; did you mean 'x'? 78 | vis[cur.xx][cur.yy]=1; | ^~ | x a.cc:78:25: error: 'struct node' has no member named 'yy'; did you mean 'y'? 78 | vis[cur.xx][cur.yy]=1; | ^~ | y
s485886419
p03725
C++
#include<bits/stdc++.h> #define up(j,k,i) for(ll i=j;i<k;i++) #define down(j,k,i) for(ll i=j;i>k;i--) #define M 1000000007 #define pp(n) printf("%lld\n",ll(n)) #define ps(n) printf("%lld ",ll(n)) #define pd(x,y) printf("%lld %lld\n",ll(x),ll(y)) #define is(n) scanf("%lld",&n) #define inf 1e15 #define id(n,m) scanf("%lld%lld",&n,&m) #define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k) #define ss(s) scanf("%s",s) #define cool 0 #define pb push_back #define mp make_pair #define F first #define S second #define pll pair<ll,ll> #define db cout<<"######\n" #define null(a) memset(a,0,sizeof(a)) #define neg(a) memset(a,255,sizeof(a)) typedef long double ld; typedef long long int ll; using namespace std; ll i,j,k,z,t,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag; ll dist[805][805]; vector<pll> reach; char a[805][805]; inline ll ceil(ll x,ll y) { if(x%y) return x/y+1; else return x/y; } bool check(ll x, ll y) { if(x<1||x>n||y<1||y>m) return false; else if(a[x][y]=='#') return false; else return true; } ll dx[4]={1,0,-1,0}; ll dy[4]={0,1,0,-1}; void bfs(ll x,ll y) { dist[x][y]=0; priority_queue<pair<ll,pll>,vector<pair<ll,pll>>, greater<pair<ll,pll> >> Q; Q.push({0,{x,y}}); while(!Q.empty()) { auto c=Q.top(); Q.pop(); z=c.F; x=c.S.F; y=c.S.S; if(z>k) continue; else reach.pb({x,y}); up(0,4,i) if(check(x+dx[i],y+dy[i])) if(dist[x+dx[i]][y+dy[i]]>z+1) dist[x+dx[i]][y+dy[i]]=z+1,Q.push({z+1,{x+dx[i],y+dy[i]}}); } } int main() { it(n,m,k); up(1,n+1,i) up(1,m+1,j) { cin>>a[i][j]; if(a[i][j]=='') x=i,y=j; dist[i][j]=inf; } if(x==1 or y==1) { pp(0); return 0; } bfs(x,y); ans=inf; for(auto c:reach) { ans=min(ans,min(min(ceil(n-c.F,k),ceil(c.F-1,k)),min(ceil(m-c.S,k),ceil(c.S-1,k)))+1); } pp(ans); }
a.cc:81:29: error: empty character constant 81 | if(a[i][j]=='') | ^~
s161619848
p03725
C++
#include <iostream> #include <string> #include <vector> #include <stack> #include <algorithm> #include <cmath> int main() { long long h, w, k, sx, sy; std::cin >> h >> w >> k; std::vector<std::string> v(h); for (long long i = 0; i < h; i++) { std::cin >> v[i]; auto pos = std::find(v[i].begin(), v[i].end(), 'S'); if (pos != v[i].end()) { sx = i; sy = pos - v[i].begin(); } } std::stack<std::pair<long long, long long> > s, p; s.push({ sx, sy }); p.push({ sx, sy }); int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 }; while (!s.empty()) { int x = s.top().first, y = s.top().second; s.pop(); for (int i = 0; i < 4; i++) { if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) { continue; } if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) { continue; } if (v[x + xx[i]][y + yy[i]] == '.') { s.push({ x + xx[i], y + yy[i] }); p.push({ x + xx[i], y + yy[i] }); v[x + xx[i]][y + yy[i]] = '#' // 一度行った場所に行かないようにする } } } long long ans = 1000000000000; while(!p.empty()){ long long x = p.top().first, y = p.top().second; p.pop(); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k))); } std::cout << ans + 1 << std::endl; return 0; }
a.cc: In function 'int main()': a.cc:43:62: error: expected ';' before '}' token 43 | v[x + xx[i]][y + yy[i]] = '#' // 一度行った場所に行かないようにする | ^ | ; 44 | } | ~
s821718451
p03725
C++
#include <iostream> #include <string> #include <vector> #include <stack> #include <algorithm> int main() { long long h, w, k, sx, sy; std::cin >> h >> w >> k; std::vector<std::string> v(h); for (long long i = 0; i < h; i++) { std::cin >> v[i]; auto pos = std::find(v[i].begin(), v[i].end(), 'S'); if (pos != v[i].end()) { sx = i; sy = pos - v[i].begin(); } } std::stack<std::pair<long long, long long> > s, p; s.push({ sx, sy }); p.push({ sx, sy }); int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 }; while (!s.empty()) { int x = s.top().first, y = s.top().second; s.pop(); for (int i = 0; i < 4; i++) { if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) { continue; } if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) { continue; } if (v[x + xx[i]][y + yy[i]] == '.') { s.push({ x + xx[i], y + yy[i] }); p.push({ x + xx[i], y + yy[i] }); } } } long long ans = 1000000000000; while(!p.empty()){ long long x = p.top().first, y = p.top().second; p.pop(); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k))); } std::cout << ans + 1 << std::endl; return 0; }
a.cc: In function 'int main()': a.cc:50:65: error: 'ceil' is not a member of 'std' 50 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k))); | ^~~~ a.cc:51:65: error: 'ceil' is not a member of 'std' 51 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k))); | ^~~~ a.cc:52:65: error: 'ceil' is not a member of 'std' 52 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k))); | ^~~~ a.cc:53:65: error: 'ceil' is not a member of 'std' 53 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k))); | ^~~~
s590685358
p03725
C++
#include <iostream> #include <string> #include <vector> #include <stack> int main() { long long h, w, k, sx, sy; std::cin >> h >> w >> k; std::vector<std::string> v(h); for (long long i = 0; i < h; i++) { std::cin >> v[i]; auto pos = std::find(v[i].begin(), v[i].end(), 'S'); if (pos != v[i].end()) { sx = i; sy = pos - v[i].begin(); } } std::stack<std::pair<long long, long long> > s, p; s.push({ sx, sy }); p.push({ sx, sy }); int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 }; while (!s.empty()) { int x = s.top().first, y = s.top().second; s.pop(); for (int i = 0; i < 4; i++) { if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) { continue; } if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) { continue; } if (v[x + xx[i]][y + yy[i]] == '.') { s.push({ x + xx[i], y + yy[i] }); p.push({ x + xx[i], y + yy[i] }); } } } long long ans = 1000000000000; while(!p.empty()){ long long x = p.top().first, y = p.top().second; p.pop(); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k))); ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k))); } std::cout << ans + 1 << std::endl; return 0; }
a.cc: In function 'int main()': a.cc:16:37: error: no matching function for call to 'find(std::__cxx11::basic_string<char>::iterator, std::__cxx11::basic_string<char>::iterator, char)' 16 | auto pos = std::find(v[i].begin(), v[i].end(), 'S'); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/bits/locale_facets.h:48, from /usr/include/c++/14/bits/basic_ios.h:37, from /usr/include/c++/14/ios:46, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT> >::__type std::find(istreambuf_iterator<_CharT>, istreambuf_iterator<_CharT>, const _CharT2&)' 435 | find(istreambuf_iterator<_CharT> __first, | ^~~~ /usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: template argument deduction/substitution failed: a.cc:16:37: note: '__gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >' is not derived from 'std::istreambuf_iterator<_CharT>' 16 | auto pos = std::find(v[i].begin(), v[i].end(), 'S'); | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:49:65: error: 'ceil' is not a member of 'std' 49 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k))); | ^~~~ a.cc:50:65: error: 'ceil' is not a member of 'std' 50 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k))); | ^~~~ a.cc:51:65: error: 'ceil' is not a member of 'std' 51 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k))); | ^~~~ a.cc:52:65: error: 'ceil' is not a member of 'std' 52 | ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k))); | ^~~~
s637859219
p03725
C++
#include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; const int M = 1e3; char mmp[M][M], s[M][M]; int h, w, k, step[M][M], dr[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; struct TnT { int x, y, step, flag; }; bool vis[M][M]; void bfs(TnT sta) { memset(step, 0, sizeof(step)); step[sta.x][sta.y] = 1; memset(vis, false, sizeof(vis)); vis[sta.x][sta.y] = true; queue<TnT>q; q.push(sta); while (!q.empty()) { TnT gg = q.front(); q.pop(); for (int i = 0 ; i < 4 ; i++) { TnT gl = gg; gl.x += dr[i][0]; gl.y += dr[i][1]; if (gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !vis[gl.x][gl.y]) { gl.step++; step[gl.x][gl.y] = gl.step; vis[gl.x][gl.y] = true; q.push(gl); } } } } int main(void) { scanf("%d%d%d", &h, &w, &k); for (int i = 0 ; i < h ; i++) scanf("%s", mmp[i]); TnT sta; for (int i = 0 ; i < h ; i++) { for (int j = 0 ; j < w ; j++) { if (mmp[i][j] == 'S') { sta.x = i, sta.y = j; break; } } } sta.step = 0, sta.flag = k; bfs(sta); int ans = 1000000000; for (int i = 0 ; i < h ; i++) { for (int j = 0 ; j < w ; j++) { if (step[i][j] != 0) { int gg = step[i][j], gl = 0; gl = gg / k + (gg % k != 0); gg = i; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = j; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = h - 1 - i; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = w - 1 - j; ans = min(ans, gl + gg / k + (gg % k != 0)); } } } } printf("%d\n", ans); return 0; }
a.cc:81:11: error: expected constructor, destructor, or type conversion before '(' token 81 | printf("%d\n", ans); | ^ a.cc:82:5: error: expected unqualified-id before 'return' 82 | return 0; | ^~~~~~ a.cc:83:1: error: expected declaration before '}' token 83 | } | ^
s603929623
p03725
C++
#include <iostream> #include <cstring> #include <cstdio> #include <queue> using namespace std; const int M = 1e3; char mmp[M][M], s[M][M]; int h, w, k, step[M][M], dr[4][2] = {1, 0, -1, 0, 0, 1, 0, -1}; struct TnT { int x, y, step, flag; }; bool vis[M][M]; void bfs(TnT sta) { memset(step, 0, sizeof(step)); step[sta.x][sta.y] = 1; memset(vis, false, sizeof(vis)); vis[sta.x][sta.y] = true; queue<TnT>q; q.push(sta); while (!q.empty()) { TnT gg = q.front(); q.pop(); for (int i = 0 ; i < 4 ; i++) { TnT gl = gg; gl.x += dr[i][0]; gl.y += dr[i][1]; if (gl.x >= 0 && gl.x < h && gl.y >= 0 && gl.y < w && mmp[gl.x][gl.y] != '#' && !vis[gl.x][gl.y]) { gl.step++; step[gl.x][gl.y] = gl.step; vis[gl.x][gl.y] = true; q.push(gl); } } } } int main() { scanf("%d%d%d", &h, &w, &k); for (int i = 0 ; i < h ; i++) scanf("%s", mmp[i]); TnT sta; for (int i = 0 ; i < h ; i++) { for (int j = 0 ; j < w ; j++) { if (mmp[i][j] == 'S') { sta.x = i, sta.y = j; break; } } } sta.step = 0, sta.flag = k; bfs(sta); int ans = 1000000000; for (int i = 0 ; i < h ; i++) { for (int j = 0 ; j < w ; j++) { if (step[i][j] != 0) { if (i == 0 || i == h - 1 || j == 0 || j == w - 1)//在边缘 { int gg = step[i][j]; ans = min(ans, gg / k + (gg % k != 0)); } else { int gl = step[i][j] / k + (gg % k != 0);//可以变gl次 int gg = i; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = j; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = h - 1 - i; ans = min(ans, gl + gg / k + (gg % k != 0)); gg = w - 1 - j; ans = min(ans, gl + gg / k + (gg % k != 0)); } } } } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:74:48: error: 'gg' was not declared in this scope; did you mean 'gl'? 74 | int gl = step[i][j] / k + (gg % k != 0);//可以变gl次 | ^~ | gl
s117574550
p03725
C++
#include <iostream> #include <vector> #include <queue> #include <unordered_set> #include <map> #include <algorithm> using namespace std; const int dy[4] = {1, 0, -1, 0}; const int dx[4] = {0, 1, 0, -1}; int H, W, K; class Coord { public: int y, x, k; Coord(int i, int j, int _k) { y = i; x = j; k = _k; } void setNextCoord(vector<Coord>& v) { for (int i=0; i<4; i++) { if (k+1 > K) continue; v.push_back(Coord(y+dy[i], x+dx[i], k+1)); } } int hash() { return y*W + x; } int remain() { return min(min(y, H-y-1), min(x, W-x-1)); } }; int main() { cin >> H >> W >> K; vector<String> A(H); unordered_set<int> st; queue<Coord> que; for (int i=0; i<H; i++) { cin >> A[i]; for (int j=0; j<W; j++) { if (A[i][j] == 'S') que.push(Coord(i, j, 0)); } } int minRemain = 801; vector<Coord> nextCoord; while (!que.empty()) { Coord c = que.front(); que.pop(); st.insert(c.hash()); cout << c.y <<","<< c.x <<","<< c.k <<"/"<< c.remain() << endl; minRemain = c.remain() < minRemain ? c.remain() : minRemain; if (minRemain == 0) break; nextCoord.clear(); c.setNextCoord(nextCoord); for (Coord nc : nextCoord) { if (st.find(nc.hash()) != st.end()) continue; if (A[nc.y][nc.x] == '#') continue; que.push(nc); } } cout << 1 + (minRemain+K-1)/K << endl; return 0; }
a.cc: In function 'int main()': a.cc:33:12: error: 'String' was not declared in this scope 33 | vector<String> A(H); | ^~~~~~ a.cc:33:18: error: template argument 1 is invalid 33 | vector<String> A(H); | ^ a.cc:33:18: error: template argument 2 is invalid a.cc:38:17: error: invalid types 'int[int]' for array subscript 38 | cin >> A[i]; | ^ a.cc:40:18: error: invalid types 'int[int]' for array subscript 40 | if (A[i][j] == 'S') que.push(Coord(i, j, 0)); | ^ a.cc:60:18: error: invalid types 'int[int]' for array subscript 60 | if (A[nc.y][nc.x] == '#') continue; | ^
s491804383
p03725
C++
#include <vector> #include <string.h> #include<iostream> #include<set> #include<map> #include<unordered_map> #include<unordered_set> #include<string.h> #include<algorithm> #include <stdlib.h> #include<queue> using namespace std; const int mod=1e9+7; typedef long long ll; #define out_vector(v) for(auto a:v)cout<<a<<" "; cout<<endl; int h,w,k; char r[900][900]; int dp[900][900]; int main() { cin>>h>>w>>k; int sa,sb; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>r[i][j]; if(r[i][j]=='S'){ sa=i,sb=j; } } } queue<pair<pair<int,int>,int> >que; que.push(make_pair(make_pair(sa, sb),0)); int dx[4]={1,0,-1,0}; int dy[4]={0,1,0,-1}; int ans=900; while(que.size()){ auto f=que.front(); que.pop(); int x=f.first.second,y=f.first.first; double mx=min(w-1-x,x); double my=min(h-1-y,y); if(mx==0||my==0)ans=1; else ans=min(ans,1+int(ceil(min(mx,my)/k))); if(f.second+1<=k){ for(int i=0;i<4;i++){ int nx=x+dx[i],ny=y+dy[i]; if(nx>=0&&nx<w&&ny>=0&&ny<h&&r[ny][nx]=='.'){ que.push(make_pair(make_pair(ny, nx), f.second+1)); } } } } cout<<ans<<endl; }
a.cc: In function 'int main()': a.cc:47:32: error: 'ceil' was not declared in this scope 47 | else ans=min(ans,1+int(ceil(min(mx,my)/k))); | ^~~~
s111382388
p03725
C++
#include <cstdio> #include <cstring> #include <iostream> using namespace std; typedef long long ll; const int N = 1000; const int INF = 1 << 30; inline char get(void) { return getchar(); static char buf[100000], *S = buf, *T = buf; if (S == T) { T = (S = buf) + fread(buf, 1, 100000, stdin); if (S == T) return EOF; } return *S++; } template<typename T> inline void read(T &x) { static char c; x = 0; int sgn = 0; for (c = get(); c < '0' || c > '9'; c = get()) if (c == '-') sgn = 1; for (; c >= '0' && c <= '9'; c = get()) x = x * 10 + c - '0'; if (sgn) x = -x; } char ch[N][N]; int mp[N][N]; int n, m, k, sx, sy, px, py, mn, dis; int d[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}}; inline int Min(int a, int b) { return a < b ? a : b; } void dfs(int x, int y, int step) { if (step > k || mp[x][y] || x < 1 || y < 1 || x > n || y > m) { if (dis = Min(Min(x - 1, y - 1), Min(n - x, m - y)) < mn) { mn = Min(dis + 1, mn); px = x; py = y; } return; } for (int i = 0; i < 4; i++) dfs(x + d[i][0], y + d[i][1], step + 1); } int main(void) { read(n); read(m); read(k); for (int i = 1; i <= n; i++) gets(ch[i] + 1); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) if (ch[i][j] == 'S') sx = i, sy = j; else if (ch[i][j] == '#') mp[i][j] = 1; mn = INF; dfs(sx, sy, 0); cout << 1 + (mn + k - 1) / k << endl; return 0; }
a.cc: In function 'int main()': a.cc:49:32: error: 'gets' was not declared in this scope; did you mean 'getw'? 49 | for (int i = 1; i <= n; i++) gets(ch[i] + 1); | ^~~~ | getw
s215127042
p03725
C++
#include <iostream> #include<algorithm> #include<math.h> using namespace std; #define INF 10000000 int x[4]={-1,1,0,0}; int y[4]={0,0,1,-1}; int H,W,K,inf=INF; int checked[800][800]={0}; int map[800][800]; int start[2]; char s; vector<int> P; void dfs(int a,int b,int d){ checked[a][b]a=d; P.push_back(fmin(inf,fmin(fmin(a,H-1-a),fmin(b,W-1-b)))); if(d<K){ for(int i=0;i<4;i++){ int nx=a+x[i]; int ny=b+y[i]; if(map[nx][ny]&&(checked[nx][ny]==0||checked[nx][ny]>d)&&nx>-1&&nx<H&&ny<W&&ny>-1){ dfs(nx,ny,d+1); } } } } int main(void){ cin>>H>>W>>K; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cin>>s; if(s=='#')map[i][j]=0; if(s=='S'){ map[i][j]=1; start[0]=i; start[1]=j; } if(s=='.')map[i][j]=1; } } dfs(start[0],start[1],0); sort(P.begin(),P.end()); cout<<(P[0]+K-1)/K+1; }
a.cc:13:1: error: 'vector' does not name a type 13 | vector<int> P; | ^~~~~~ a.cc: In function 'void dfs(int, int, int)': a.cc:17:18: error: expected ';' before 'a' 17 | checked[a][b]a=d; | ^ | ; a.cc:18:5: error: 'P' was not declared in this scope 18 | P.push_back(fmin(inf,fmin(fmin(a,H-1-a),fmin(b,W-1-b)))); | ^ a.cc: In function 'int main()': a.cc:48:10: error: 'P' was not declared in this scope 48 | sort(P.begin(),P.end()); | ^
s938020118
p03725
C++
#include <iostream> #include <queue> using namespace std; int dx[] = { 1, -1, 0, 0 }; int dy[] = { 0, 0, 1, -1 }; int main() { int height, width, k; cin >> height >> width >> k; int startHeight; int startWidth; char grid[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { cin >> grid[i][j]; if (grid[i][j] == 'S') { startHeight = i; startWidth = j; } } } int min = 100000; int board[height][width]; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { board[i][j] = -1; } } board[statHeight][startWidth] = 0; queue<int> queueX; queue<int> queueY; queueX.push(startHeight); queueY.push(startWidth); while (queueX.size() > 0) { int x = queueX.front(); int y = queueY.front(); queueX.pop(); queueY.pop(); for (int i = 0; i < dx.size(); i++) { int nextX = x; int nextY = y; int majic = k; for (int j = 0; j < k; j++) { if ( grid[nextY + dy[i]][nextX + dx[i]] == '.' || grid[nextY + dy[i]][nextX + dx[i]] == 'S') { nextX += dx[i]; nextY += dy[i]; } else if (grid[nextY + dy[i]][nextX + dx[i]]] == "#" && k > 0) { nextX += dx[i]; nextY += dy[i]; k--; } } if ( 0 <= nextX && nextX < width && 0 <= nextY && nextY < height && board[nextY][nextX] == -1) { board[nextY][nextX] = board[y][x] + 1; queueX.push(nextX); queueY.push(nextY); } } } for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (grid[i][j] == "." && board[i][j] == -1) return -1; min = std::min(min, board[i][j]); } } return 0; }
a.cc: In function 'int main()': a.cc:37:9: error: 'statHeight' was not declared in this scope; did you mean 'startHeight'? 37 | board[statHeight][startWidth] = 0; | ^~~~~~~~~~ | startHeight a.cc:48:28: error: request for member 'size' in 'dx', which is of non-class type 'int [4]' 48 | for (int i = 0; i < dx.size(); i++) { | ^~~~ a.cc:57:54: error: expected ')' before ']' token 57 | } else if (grid[nextY + dy[i]][nextX + dx[i]]] == "#" && k > 0) { | ~ ^ | ) a.cc:57:54: error: expected primary-expression before ']' token a.cc:74:22: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 74 | if (grid[i][j] == "." && board[i][j] == -1) | ~~~~~~~~~~~^~~~~~
s077016117
p03725
Java
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int h = in.nextInt(), w = in.nextInt(), k = in.nextInt(); String[] mazes = new String[h]; for (int i = 0; i < mazes.length; i++) { mazes[i] = in.next(); } in.close(); char[][] maze = new char[h][w]; for (int i = 0; i < mazes.length; i++) { for (int j = 0; j < mazes[0].length(); j++) { maze[i][j] = mazes[i].charAt(j); } } int[] dx = { -1, 0, 1, 0 }, dy = { 0, -1, 0, 1 }; int sx = -1, sy = -1; for (int i = 1; i < maze.length - 1; ++i) { for (int j = 0; j < maze[0].length - 1; j++) { if (maze[i][j] == 'S') { sy = i; sx = j; } } } int x1, x2, y1, y2, min; x1 = sx; y1 = sy; x2 = w - 1 - sx; y2 = h - 1 - sy; min = Math.min(x1, Math.min(y1, Math.min(x2, y2))); int maxAns = min / k; if (min % k > 0) ++maxAns; ++maxAns; Queue<Pair> que = new LinkedList<>(); Queue<Pair> que2 = new LinkedList<>(); Queue<Pair> queAns = new LinkedList<>(); que.add(new Pair(sy, sx)); for (int i = 0; i <= k && !que.isEmpty();) { while (!que.isEmpty()) { Pair p = que.poll(); que2.add(p); queAns.add(p); } while (!que2.isEmpty()) { Pair p = que2.poll(); int px = p.x, py = p.y; for (int j = 0; j < dy.length; j++) { if (0 <= py + dy[j] && py + dy[j] < h && 0 <= px + dx[j] && px + dx[j] < w && maze[py + dy[j]][px + dx[j]] != '#') { que.add(new Pair(py + dy[j], px + dy[j])); maze[py + dy[j]][px + dx[j]] = '#'; } } } ++i; } while(!queAns.isEmpty()) { Pair p = queAns.poll(); sx = p.x; sy = p.y; x1 = sx; y1 = sy; x2 = w - 1 - sx; y2 = h - 1 - sy; min = Math.min(min, Math.min(x1, Math.min(y1, Math.min(x2, y2)))); } System.out.println(min); } } class Pair { int x, y; public Pair(int y, int x) { this.y = y; this.x = x; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = prime * result + y; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Pair other = (Pair) obj; if (x != other.x) return false; if (y != other.y) return false; return true; }
Main.java:121: error: reached end of file while parsing } ^ 1 error
s835458923
p03725
Java
import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class Main { public static void main(String[] args) { new Main().solve(); } int H,W,K; String[]A; void solve(){ Scanner sc=new Scanner(System.in); int count=0; H=sc.nextInt(); W=sc.nextInt(); K=sc.nextInt(); //=魔法の移動回数=開けられる部屋の個数 A=new String[H]; for(int i=0;i<H;i++){ A[i]=sc.next(); } int fx=-1; int fy=-1; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ if(A[i].charAt(j)=='S'){ fx=j; fy=i; } } } Queue<Integer> nowq=new LinkedList<Integer>(); nowq.add(encode(fy,fx)); int[] vy=new int[]{1,0,-1,0}; int[] vx=new int[]{0,1,0,-1}; boolean[][] check=new boolean[H][W]; check[fy][fx]=true; //幅優先探索 LOOP:while(true){ count++; //開けた部屋を入れるキュー Queue<Integer> nextq=new LinkedList<Integer>(); Queue<Integer>nextnextq=new LinkedList<Integer>(); while(!nowq.isEmpty()){ int now=nowq.poll(); int y=now/1000; int x=now%1000; //K回まで移動できる for(int i=0;i<K;i++){ for(int j=0;j<4;j++){ int ny=y+vy[j]; int nx=x+vx[j]; if(!ok(ny,nx))continue; if(check[ny][nx])continue; check[ny][nx]=true; if(A[ny].charAt(nx)!='#' && (ny==0 || ny==H-1 || nx==0 || nx==W-1)){ System.out.println(count); break LOOP; } else if(A[ny].charAt(nx)=='#'){ nextq.add(encode(ny,nx)); } else{ nowq.add(encode(ny,nx)); } } } } nowq=nextq; while(!nowq.isEmpty()){ int now=nowq.poll(); int y=now/1000; int x=now%1000; //K-1回まで部屋を開ける(移動する) for(int i=0;i<K-1;i++){ for(int j=0;j<4;j++){ int ny=y+vy[j]; int nx=x+vx[j]; if(!ok(ny,nx))continue; if(check[ny][nx])continue; check[ny][nx]=true; if(A[ny].charAt(nx)=='#' && (ny==0 || ny==H-1 || nx==0 || nx==W-1)){ System.out.println(count+1); break LOOP; } nextnextq.add(encode(ny,nx)); nowq.add(encode(ny,nx)); } } } nowq=nextnextq; } }
Main.java:108: error: reached end of file while parsing } ^ 1 error
s903009016
p03725
C++
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define poq pop_back #define tof ios_base :: sync_with_stdio(NULL);cin.tie(0);cout.tie(0) using namespace std; char y[809][809]; bool viz[809][809]; bool vizz[809][809]; int main() { ll h,w,k,X,Y; cin >> h >> w >> k; for (ll i=0; i<h; i++) { for (ll j=0; j<w; j++) { cin >> y[i][j]; if (y[i][j]=='S') { X=i; Y=j; } } } stack<pair<ll,ll> > stk; stack<pair<ll,ll> >sttk; stack<pair<ll,ll> >stttk; pair<ll,ll> v; stk.push(mp(X,Y)); stttk.push(mp(X,Y)); viz[X][Y]=1; ll ans=0; for (ll i=0; i<k; i++) { while(!stk.empty()) { v=stk.top(); if (v.F>0) { if (y[v.F-1][v.S]!='#') { sttk.push(mp(v.F-1,v.S)); } } else { cout<<1; return 0; } if (v.F<h-1) { if (y[v.F+1][v.S]!='#') { sttk.push(mp(v.F+1,v.S)); } } else { cout<<1; return 0; } if (v.S>0) { if (y[v.F][v.S-1]!='#') { sttk.push(mp(v.F,v.S-1)); } } else { cout<<1; return 0; } if (v.S<w-1) { if (y[v.F][v.S+1]!='#') { sttk.push(mp(v.F,v.S+1)); } } else { cout«1; return 0; } stk.pop(); } while (!sttk.empty()) { v=sttk.top(); if (v.F==0||v.S==0||v.F==h-1||v.S==w-1) { cout«1; return 0; } if (!viz[v.F][v.S]) { stk.push(v); stttk.push(v); viz[v.F][v.S]=1; } sttk.pop(); } } ans=1e9; while (!stttk.empty()) { v=stttk.top(); ans=min(ans,v.F); ans=min(ans,v.S); ans=min(ans,w-1-v.S); ans=min(ans,h-1-v.F); stttk.pop(); } if (ans%k==0) { cout<<ans/k+1; } else { cout<<ans/k+2; } //etgegeg }
a.cc:95:17: error: extended character « is not valid in an identifier 95 | cout«1; | ^ a.cc:105:17: error: extended character « is not valid in an identifier 105 | cout«1; | ^ a.cc: In function 'int main()': a.cc:95:17: error: 'cout\U000000ab1' was not declared in this scope 95 | cout«1; | ^~~~~~ a.cc:105:17: error: 'cout\U000000ab1' was not declared in this scope 105 | cout«1; | ^~~~~~
s361354333
p03725
C++
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define poq pop_back #define tof ios_base :: sync_with_stdio(NULL);cin.tie(0);cout.tie(0) using namespace std; char y[809][809]; bool viz[809][809]; bool vizz[809][809]; int main() { ll h,w,k,X,Y; cin»h»w»k; for (ll i=0; i<h; i++) { for (ll j=0; j<w; j++) { cin»y[i][j]; if (y[i][j]=='S') { X=i; Y=j; } } } stack<pair<ll,ll> > stk; stack<pair<ll,ll> >sttk; stack<pair<ll,ll> >stttk; pair<ll,ll> v; stk.push(mp(X,Y)); stttk.push(mp(X,Y)); viz[X][Y]=1; ll ans=0; for (ll i=0; i<k; i++) { while(!stk.empty()) { v=stk.top(); if (v.F>0) { if (y[v.F-1][v.S]!='#') { sttk.push(mp(v.F-1,v.S)); } } else { cout«1; return 0; } if (v.F<h-1) { if (y[v.F+1][v.S]!='#') { sttk.push(mp(v.F+1,v.S)); } } else { cout«1; return 0; } if (v.S>0) { if (y[v.F][v.S-1]!='#') { sttk.push(mp(v.F,v.S-1)); } } else { cout«1; return 0; } if (v.S<w-1) { if (y[v.F][v.S+1]!='#') { sttk.push(mp(v.F,v.S+1)); } } else { cout«1; return 0; } stk.pop(); } while (!sttk.empty()) { v=sttk.top(); if (v.F==0||v.S==0||v.F==h-1||v.S==w-1) { cout«1; return 0; } if (!viz[v.F][v.S]) { stk.push(v); stttk.push(v); viz[v.F][v.S]=1; } sttk.pop(); } } ans=1e9; while (!stttk.empty()) { v=stttk.top(); ans=min(ans,v.F); ans=min(ans,v.S); ans=min(ans,w-1-v.S); ans=min(ans,h-1-v.F); stttk.pop(); } if (ans%k==0) { cout«ans/k+1; } else { cout«ans/k+2; } }
a.cc:22:5: error: extended character » is not valid in an identifier 22 | cin»h»w»k; | ^ a.cc:22:5: error: extended character » is not valid in an identifier a.cc:22:5: error: extended character » is not valid in an identifier a.cc:27:13: error: extended character » is not valid in an identifier 27 | cin»y[i][j]; | ^ a.cc:59:17: error: extended character « is not valid in an identifier 59 | cout«1; | ^ a.cc:71:17: error: extended character « is not valid in an identifier 71 | cout«1; | ^ a.cc:83:17: error: extended character « is not valid in an identifier 83 | cout«1; | ^ a.cc:95:17: error: extended character « is not valid in an identifier 95 | cout«1; | ^ a.cc:105:17: error: extended character « is not valid in an identifier 105 | cout«1; | ^ a.cc:129:9: error: extended character « is not valid in an identifier 129 | cout«ans/k+1; | ^ a.cc:133:9: error: extended character « is not valid in an identifier 133 | cout«ans/k+2; | ^ a.cc: In function 'int main()': a.cc:22:5: error: 'cin\U000000bbh\U000000bbw\U000000bbk' was not declared in this scope 22 | cin»h»w»k; | ^~~~~~~~~ a.cc:27:13: error: 'cin\U000000bby' was not declared in this scope 27 | cin»y[i][j]; | ^~~~~ a.cc:59:17: error: 'cout\U000000ab1' was not declared in this scope 59 | cout«1; | ^~~~~~ a.cc:71:17: error: 'cout\U000000ab1' was not declared in this scope 71 | cout«1; | ^~~~~~ a.cc:83:17: error: 'cout\U000000ab1' was not declared in this scope 83 | cout«1; | ^~~~~~ a.cc:95:17: error: 'cout\U000000ab1' was not declared in this scope 95 | cout«1; | ^~~~~~ a.cc:105:17: error: 'cout\U000000ab1' was not declared in this scope 105 | cout«1; | ^~~~~~ a.cc:129:9: error: 'cout\U000000abans' was not declared in this scope 129 | cout«ans/k+1; | ^~~~~~~~ a.cc:133:9: error: 'cout\U000000abans' was not declared in this scope 133 | cout«ans/k+2; | ^~~~~~~~
s708093596
p03725
C++
#include<bits/stdc++.h> using namespace std; long long H, W, K; long long A[805][805]; long long WORK[805][805]; #define OPEN INT_MAX #define CLOSED LONG_MAX/3 bool valid(long long h, long long w){ return (h >= 0) && (h < H) && (w >= 0) && (w < W); } void move(long long h, long long w, long long cost){ if(valid(h, w) == false || A[h][w] == CLOSED || cost > K || A[h][w] <= cost){ return; } A[h][w] = cost; move(h-1, w, cost+1); move(h+1, w, cost+1); move(h, w-1, cost+1); move(h, w+1, cost+1); } void firstmove(){ for(long long h = 0; h < H; h++){ for(long long w = 0; w < W; w++){ if(A[h][w] == 1){ move(h, w, 0); return; } } } } int main(){ cin >> H >> W >> K; for(long long h = 0; h < H; h++){ string S; cin >> S; for(long long w = 0; w < W; w++){ if(S[w] == '.'){ A[h][w] = OPEN; }else if(S[w] == 'S'){ A[h][w] = 1; }else{ A[h][w] = CLOSED; } } } firstmove(); long long ans = INT_MAX; for(long long h = 0; h < H; h++){ for(long long w = 0; w < W; w++){ if(A[h][w] != OPEN && A[h][w] != CLOSED){ long long tmp; tmp = h; tmp = min(tmp, w); tmp = min(tmp, H - h - 1); tmp = min(tmp, W - w - 1); if(tmp % K == 0){ ans = min(ans, tmp/K); }else{ ans = min(ans, tmp/K + 1); } } } } cout << ans + 1 << endl; }
In file included from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h: In instantiation of '_OI std::__copy_move_a2(_II, _II, _OI) [with bool _IsMove = true; _II = long long int; _OI = int]': /usr/include/c++/14/bits/stl_algobase.h:548:42: required from '_OI std::__copy_move_a1(_II, _II, _OI) [with bool _IsMove = true; _II = long long int; _OI = int]' 548 | { return std::__copy_move_a2<_IsMove>(__first, __last, __result); } | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:556:31: required from '_OI std::__copy_move_a(_II, _II, _OI) [with bool _IsMove = true; _II = long long int; _OI = int]' 556 | std::__copy_move_a1<_IsMove>(std::__niter_base(__first), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 557 | std::__niter_base(__last), | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 558 | std::__niter_base(__result))); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:683:38: required from '_OI std::move(_II, _II, _OI) [with _II = long long int; _OI = int]' 683 | return std::__copy_move_a<true>(std::__miter_base(__first), | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ 684 | std::__miter_base(__last), __result); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:32:9: required from here 32 | move(h, w, 0); | ~~~~^~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:514:64: error: no type named 'iterator_category' in 'struct std::iterator_traits<long long int>' 514 | typedef typename iterator_traits<_II>::iterator_category _Category; | ^~~~~~~~~ /usr/include/c++/14/bits/stl_algobase.h:521:51: error: no type named 'iterator_category' in 'struct std::iterator_traits<long long int>' 520 | return std::__copy_move<_IsMove, __memcpyable<_OI, _II>::__value, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 521 | _Category>::__copy_m(__first, __last, __result); | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
s624966357
p03725
C++
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define poq pop_back #define tof ios_base :: sync_with_stdio(NULL);cin.tie(0);cout.tie(0) using namespace std; char y[809][809]; bool viz[809][809]; bool vizz[809][809]; int main() { ll h,w,k,X,Y; cin»h»w»k; for (ll i=0; i<h; i++) { for (ll j=0; j<w; j++) { cin»y[i][j]; if (y[i][j]=='S') { X=i; Y=j; } } } stack<pair<ll,ll> > stk; stack<pair<ll,ll> >sttk; stack<pair<ll,ll> >stttk; pair<ll,ll> v; stk.push(mp(X,Y)); stttk.push(mp(X,Y)); viz[X][Y]=1; ll ans=0; for (ll i=0; i<k; i++) { while(!stk.empty()) { v=stk.top(); if (v.F>0) { if (y[v.F-1][v.S]!='#') { sttk.push(mp(v.F-1,v.S)); } } else { cout«1; return 0; } if (v.F<h-1) { if (y[v.F+1][v.S]!='#') { sttk.push(mp(v.F+1,v.S)); } } else { cout«1; return 0; } if (v.S>0) { if (y[v.F][v.S-1]!='#') { sttk.push(mp(v.F,v.S-1)); } } else { cout«1; return 0; } if (v.S<w-1) { if (y[v.F][v.S+1]!='#') { sttk.push(mp(v.F,v.S+1)); } } else { cout«1; return 0; } stk.pop(); } while (!sttk.empty()) { v=sttk.top(); if (v.F==0||v.S==0||v.F==h-1||v.S==w-1) { cout«1; return 0; } if (!viz[v.F][v.S]) { stk.push(v); stttk.push(v); viz[v.F][v.S]=1; } sttk.pop(); } } ans=1e9; while (!stttk.empty()) { v=stttk.top(); ans=min(ans,v.F); ans=min(ans,v.S); ans=min(ans,w-1-v.S); ans=min(ans,h-1-v.F); stttk.pop(); } if (ans%k==0) { cout«ans/k+1; } else { cout«ans/k+2; } //efetertgete }
a.cc:22:5: error: extended character » is not valid in an identifier 22 | cin»h»w»k; | ^ a.cc:22:5: error: extended character » is not valid in an identifier a.cc:22:5: error: extended character » is not valid in an identifier a.cc:27:13: error: extended character » is not valid in an identifier 27 | cin»y[i][j]; | ^ a.cc:59:17: error: extended character « is not valid in an identifier 59 | cout«1; | ^ a.cc:71:17: error: extended character « is not valid in an identifier 71 | cout«1; | ^ a.cc:83:17: error: extended character « is not valid in an identifier 83 | cout«1; | ^ a.cc:95:17: error: extended character « is not valid in an identifier 95 | cout«1; | ^ a.cc:105:17: error: extended character « is not valid in an identifier 105 | cout«1; | ^ a.cc:129:9: error: extended character « is not valid in an identifier 129 | cout«ans/k+1; | ^ a.cc:133:9: error: extended character « is not valid in an identifier 133 | cout«ans/k+2; | ^ a.cc: In function 'int main()': a.cc:22:5: error: 'cin\U000000bbh\U000000bbw\U000000bbk' was not declared in this scope 22 | cin»h»w»k; | ^~~~~~~~~ a.cc:27:13: error: 'cin\U000000bby' was not declared in this scope 27 | cin»y[i][j]; | ^~~~~ a.cc:59:17: error: 'cout\U000000ab1' was not declared in this scope 59 | cout«1; | ^~~~~~ a.cc:71:17: error: 'cout\U000000ab1' was not declared in this scope 71 | cout«1; | ^~~~~~ a.cc:83:17: error: 'cout\U000000ab1' was not declared in this scope 83 | cout«1; | ^~~~~~ a.cc:95:17: error: 'cout\U000000ab1' was not declared in this scope 95 | cout«1; | ^~~~~~ a.cc:105:17: error: 'cout\U000000ab1' was not declared in this scope 105 | cout«1; | ^~~~~~ a.cc:129:9: error: 'cout\U000000abans' was not declared in this scope 129 | cout«ans/k+1; | ^~~~~~~~ a.cc:133:9: error: 'cout\U000000abans' was not declared in this scope 133 | cout«ans/k+2; | ^~~~~~~~
s714896033
p03725
C++
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> using namespace std; #define PI acos(-1.0) #define FOR(I,A,B) for(int I = (A); I < (B); ++I) typedef long long ll; int pos(int y, int x){ return 1000 * y + x; } int main(){ int H, W, K; cin >> H >> W >> K; vector<string> vs; int S; FOR(i,0,H){ string in; cin >> in; vs.push_back(in); FOR(j,0,in.length()){ if(in[j]=='S'){ S = pos(i, j); } } } int vx[4] = {0,1,0,-1}; int vy[4] = {-1,0,1,0}; queue<int> que; que.push(S); int MIN = min(min(S/1000, abs(H-1-S/1000)), min(S%1000, abs(W-1-S%1000))); int k = 0; while(!que.empty()){ int q = que.front();que.pop(); int nowy = q/1000; int nowx = q%1000; FOR(i,0,4){ int nexty = nowy + vy[i]; int nextx = nowx + vx[i]; if(vs[nexty][nextx]=='#') continue; que.push(pos(nexty, nextx)); MIN = min(MIN, min(min(nexty, abs(H-1-nexty)),min(nextx, abs(W-1-nextx)))); } k++; if(k==K) break; } if(MIN==0) cout << 1 < <endl; else cout << (MIN+K-1)/K+1 << endl; }
a.cc: In function 'int main()': a.cc:60:28: error: expected primary-expression before '<' token 60 | if(MIN==0) cout << 1 < <endl; | ^
s647316932
p03725
C++
#include <bits/stdc++.h> #define X first #define Y second #define pb push_back #define mp make_pair using namespace std; int w, h, k; char ch[810][810]; bool vis[810][810]; const int xx[4] = {0, 1, 0, -1}; const int yy[4] = {1, 0, -1, 0}; vector<pair<int, int> > pt; void dfs(int x, int y, int time) { if(time > k) return; pt.push_back(mp(x, y)) for(int i = 0; i < 4; i ++) { int u = x + xx[i]; int v = y + yy[i]; if(u <= 0) continue; if(v <= 0) continue; if(u > w) continue; if(v > h) continue; if(vis[u][v]) continue; if(ch[u][v] == '#') continue; vis[u][v] = 1; dfs(u, v, time + 1); } } int main() { cin >> h >> w >> k; for(int i = 1; i <= w; i ++) scanf("%s", ch[i] + 1); int stx, sty; for(int i = 1; i <= w; i ++) for(int j = 1; j <= h; j ++) if(ch[i][j] == 'S') {stx = i; sty = j; break;} if(stx == 1 || sty == 1 || stx == w || sty == h) {cout << 0 << endl; return;} //cout << stx << " " << sty << endl; vis[stx][sty] = 1; dfs(stx, sty, 0); int n = pt.size(), dis = 1e7; for(int i = 0; i < n; i ++) { int x = pt[i].X; int y = pt[i].Y; dis = min(dis, x - 1); dis = min(dis, y - 1); dis = min(dis, w - x); dis = min(dis, h - y); } cout << 1 + ceil((double)dis / k); return 0; }
a.cc: In function 'void dfs(int, int, int)': a.cc:19:31: error: expected ';' before 'for' 19 | pt.push_back(mp(x, y)) | ^ | ; 20 | for(int i = 0; i < 4; i ++) | ~~~ a.cc:20:24: error: 'i' was not declared in this scope 20 | for(int i = 0; i < 4; i ++) | ^ a.cc: In function 'int main()': a.cc:46:78: error: return-statement with no value, in function returning 'int' [-fpermissive] 46 | if(stx == 1 || sty == 1 || stx == w || sty == h) {cout << 0 << endl; return;} | ^~~~~~
s785827032
p03725
C++
#include <stdio.h> #include <queue> using namespace std; int H,W,K; char map[808][808]; int dist[808][808]; int main() { scanf ("%d %d %d",&H,&W,&K); queue<pair<int, int> > Q; for (int i=0;i<H;i++){ scanf ("%s",map[i]); for (int j=0;j<W;j++){ dist[i][j] = -1; if (map[i][j] == 'S'){ Q.push({i,j}); dist[i][j] = 0; } } } while (!Q.empty()){ int x = Q.front().first, y = Q.front().second; Q.pop(); int dx[4] = {0,1,0,-1}; int dy[4] = {1,0,-1,0}; for (int k=0;k<4;k++){ int px = x + dx[k], py = y + dy[k]; if (px < 0 || px >= H || py < 0 || py >= W) continue; if (dist[px][py] == -1 && map[px][py] != '#'){ Q.push({px,py}); dist[px][py] = dist[x][y] + 1; } } } int ans = 0x7fffffff; for (int i=0;i<H;i++) for (int j=0;j<W;j++) if (dist[i][j] != -1 && dist[i][j] <= K){ int r = (min({i,H-i-1,j,W-j-1}) + K - 1) / K + 1; ans = min(r,ans); } printf ("%d\n",ans); return 0; }
a.cc: In function 'int main()': a.cc:36:29: error: no matching function for call to 'min(<brace-enclosed initializer list>)' 36 | int r = (min({i,H-i-1,j,W-j-1}) + K - 1) / K + 1; | ~~~^~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/deque:62, from /usr/include/c++/14/queue:62, from a.cc:2: /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)' 233 | min(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)' 281 | min(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate expects 3 arguments, 1 provided
s843167691
p03725
C++
#include <iostream> #include <stdio.h> #include <queue> using namespace std; char str[888][888]; int sx,sy; int dx[]={-1,1,0,0}; int dy[]={0,0,-1,1}; struct node { int x,y; }; int dp[888][888]; int vis[888][888]; int h,w,k; void BFS() { node a,b,c; a.x=sx; a.y=sy; queue<node> que; while(!que.empty()) que.pop(); que.push(a); vis[a.x][a.y]=1; int f=0; while(!que.empty()) { b=que.front(); que.pop(); for(int i=0;i<4;i++) { c.x=b.x+dx[i]; c.y=b.y+dy[i]; if(c.x>=0 && c.x<h && c.y>=0 && c.y<w && !vis[c.x][c.y]) { vis[c.x][c.y]=1; if(str[c.x][c.y]!=str[b.x][b.y] ) { dp[c.x][c.y]=dp[b.x][b.y]+1; f=0; } else if(f>k) { dp[c.x][c.y]=dp[b.x][b.y]+1; f=0; } else { dp[c.x][c.y]=dp[b.x][b.y]; f++; } que.push(c); } } } } int main() { scanf("%d %d %d",&h,&w,&k); for(int i=0;i<h;i++) { scanf("%s",str[i]); for(int j=0;j<w;j++) { if(str[i][j]=='S') { sx=i; sy=j; } } } str[sx][sy]='.'; BFS(); int mins=INT_MAX; for(int i=0;i<w;i++) { mins=min(mins,dp[0][i]+1); mins=min(mins,dp[h-1][i]+1); } for(int i=0;i<h;i++) { mins=min(mins,dp[i][0]+1); mins=min(mins,dp[w-1][i]+1); } cout<<mins<<endl; return 0; }
a.cc: In function 'int main()': a.cc:82:14: error: 'INT_MAX' was not declared in this scope 82 | int mins=INT_MAX; | ^~~~~~~ a.cc:4:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 3 | #include <queue> +++ |+#include <climits> 4 |
s791224109
p03725
C++
#include <bits/stdc++.h> #define int long long #define double long double using namespace std; template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); } template<class T> T sqr(T x) { return x*x; } template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; } int toint(string s) { int v; stringstream i(s); i >> v; return v; } bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; } int gcd(int a, int b) { return b ? gcd(b, a%b) : a; } int lcm(int a, int b) { return a / gcd(a, b) * b; } #define REP(i,a,b) for(int (i) = (a);i < (b);(i)++) #define rep(i,n) REP(i,0,n) #define PER(i,a,b) for(int (i) = (a-1);i >= (b);(i)--) #define per(i,n) PER(i,n,0) #define each(i,n) for(auto &i : n) #define clr(a) memset((a), 0 ,sizeof(a)) #define mclr(a) memset((a), -1 ,sizeof(a)) #define all(a) (a).begin(),(a).end() #define dump(val) cerr << #val " = " << val << endl; #define dum(val) cerr << #val " = " << val; #define FILL(a,v) fill(a,a+sizeof(a)/sizeof(*a),v) const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 }; const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 }; const int mod = 1e9 + 7; const int INF = 1e9; typedef tuple<int,int,int,int> F; int vis[801][801]; signed main() { int h, w, k; cin >> h >> w >> k; int sy, sx; vector<string> s(h); rep(y, h){ cin >> s[y]; rep(x, w){ if(s[y][x] == 'S'){ sy = y;sx = x; } } } auto ok = [&](int m){ vector<string> t = s; clr(vis); queue<F> q; q.push(F(sy, sx, 0, 0)); rep(i, w)rep(j, h){ vis[j][i] = INF; } vis[sy][sx] = 0 while(q.size()){ auto now = q.front(); q.pop(); int y = get<0>(now); int x = get<1>(now); int mv = get<2>(now); int us = get<3>(now); if(mv > m * k)continue; if(mv && mv % k == 0) us += k; if(x == 0 || y == 0 || x == w - 1 || y == h - 1){ return true; } rep(i, 4){ int tx = x + dx[i], ty = y + dy[i]; if(check(tx, ty, w, h) && vis[ty][tx] > mv + 1){ if(s[ty][tx] == '#'){ if(us){ q.push(F(ty, tx, mv + 1, us - 1)); }else continue; }else{ q.push(F(ty, tx, mv + 1, us)); } vis[ty][tx] = mv + 1; } } bool ok = false; rep(i, 4){ int tx = x + dx[i], ty = y + dy[i]; if(check(tx, ty, w, h) && vis[ty][tx] > (mv / k + 1) * k + 1){ ok = true; } } if(ok){ q.push(F(y, x, (mv / k + 1) * k , us)); } } return false; }; int l = 0, r = INF; rep(i, 100) { int m = (r + l) / 2.0; if (ok(m)) { r = m; } else { l = m; } } cout << r << endl; return 0; }
a.cc: In lambda function: a.cc:64:32: error: expected ';' before 'while' 64 | vis[sy][sx] = 0 | ^ | ; 65 | 66 | while(q.size()){ | ~~~~~
s280369647
p03725
C++
#include<bits/stdc++.h> using namespace std; const int move[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; #define INF 0x3f3f3f3f template<typename T> void read(T &x) { char ch=getchar(); int f=1; for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar()); if (ch=='-') f=-1,ch=getchar(); for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar()); x*=f; } int n,m,k,ans,x,y; char mp[810][810]; bool vis[810][810]; char getopt() { char ch=getchar(); while (ch!='#'&&ch!='.'&&ch!='S') ch=getchar(); return ch; } int calc(int x,int y) { return min(min(x-1,n-x),min(y-1,m-y))/k; } void dfs(int x,int y,int deep) { vis[x][y]=1; ans=min(ans,calc(x,y)); for (int i=0;i<4;i++) { int newx=x+move[i][0]; int newy=y+move[i][1]; if (deep<k&&newx>=1&&newx<=n&&newy>=1&&newy<=m&&mp[newx][newy]=='.'&&!vis[newx][newy]) dfs(newx,newy,deep+1); } } int main() { read(n),read(m),read(k); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) { mp[i][j]=getopt(); if (mp[i][j]=='S') x=i,y=j; } ans=INF; dfs(x,y,0); printf("%d",ans+1); return 0; }
a.cc: In function 'void dfs(int, int, int)': a.cc:34:28: error: reference to 'move' is ambiguous 34 | int newx=x+move[i][0]; | ^~~~ In file included from /usr/include/c++/14/algorithm:86, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ In file included from /usr/include/c++/14/algorithm:60: /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:61, from /usr/include/c++/14/bits/stl_algobase.h:64: /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:3:11: note: 'const int move [4][2]' 3 | const int move[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; | ^~~~ a.cc:35:28: error: reference to 'move' is ambiguous 35 | int newy=y+move[i][1]; | ^~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:353:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator2> std::move(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2)' 353 | move(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __d_first); | ^~~~ /usr/include/c++/14/bits/stl_algobase.h:675:5: note: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)' 675 | move(_II __first, _II __last, _OI __result) | ^~~~ /usr/include/c++/14/bits/move.h:137:5: note: 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)' 137 | move(_Tp&& __t) noexcept | ^~~~ a.cc:3:11: note: 'const int move [4][2]' 3 | const int move[4][2]={{0,1},{0,-1},{1,0},{-1,0}}; | ^~~~
s698743387
p03725
C++
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <map> #include <queue> #include <functional> using namespace std; #define INF (int)1e7 int N, M, K; vector<vector<int>>Room; int status[800][800]; int cost[800][800]; int v[] = { -1, 0, 1, 0 }; int h[] = { 0, 1, 0, -1 }; vector<pair<int,int>> dijkstra(pair<int,int>s) { vector<pair<int, int>>pos; for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { status[i][j] = 0; cost[i][j] = INF; } } cost[s.first][s.second] = 0; status[s.first][s.second] = 1; priority_queue<pair<int, pair<int,int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>>U; U.push(make_pair(cost[s.first][s.second], s)); while (!U.empty()) { //探索が終わってない中でコスト最小の点 pair<int,int>u = U.top().second; U.pop(); if (status[u.first][u.second] == -1) continue; pos.push_back(u); status[u.first][u.second] = -1; //コスト最少の点を探る for (int i = 0; i < 4; i++) { if (status[u.first + v[i]][u.second + h[i]] != -1 && u.first + v[i]>= 0 && u.second + h[i]>= 0 && u.first + v[i] < N && u.second + h[i] < M) { if (Room[u.first + v[i]][u.second + h[i]])continue; if (cost[u.first + v[i]][u.second + h[i]] == K)continue; if (cost[u.first + v[i]][u.second + h[i]] > cost[u.first][u.second] + 1) { cost[u.first + v[i]][u.second + h[i]] = cost[u.first][u.second] + 1; status[u.first + v[i]][u.second + h[i]] = 1; U.push(make_pair(cost[u.first + v[i]][u.second + h[i]], make_pair(u.first + v[i], u.second + h[i]))); } } } } return pos; } int main() { cin >> N >> M >> K; Room.resize(N); pair<int, int>pos; for (int i = 0; i < N; i++) { Room[i].resize(M); for (int j = 0; j < M; j++) { char c; cin >> c; if (c == '#')Room[i][j] = 1; else if (c == 'S')pos = make_pair(i, j); } } vector<pair<int,int>>nextpos = dijkstra(pos); vector<int>ans; for (int k = 0; k < nextpos.size(); k++) { int dist = min(min(nextpos[k].first,N - 1 - nextpos[k].first), min(nextpos[k].second, M - 1 - nextpos[k].second)); ans.push_back(dist); } sort(ans.begin(), ans.end()); cout << int(ceil((double)ans[0] / K)) + 1 << endl; return 0; }
a.cc: In function 'int main()': a.cc:79:21: error: 'ceil' was not declared in this scope 79 | cout << int(ceil((double)ans[0] / K)) + 1 << endl; | ^~~~
s808339076
p03725
C++
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> typedef long long LL; using namespace std; #define MP make_pair int n, m, k; char s[1005][1005]; int vis[1005][1005]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int main() { scanf("%d%d%d", &n, &m, &k); int x, y; memset(vis, -1, sizeof(vis)); for (int i = 0; i < n; ++i) { scanf("%s", s[i]); for (int j = 0; j < m; ++j) { if (s[i][j] == 'S') { x = i; y = j; s[i][j] = '.'; } } } queue<pair<int, int>> q; q.push(MP(x, y)); vis[x][y] = 0; while (!q.empty()) { auto w = q.front(); // cout << w.first <<" "<<w.second<<endl; q.pop(); if (vis[w.first][w.second] == k) continue; for (int i = 0; i < 4; ++i) { int nx = w.first + dx[i]; int ny = w.second + dy[i]; if (nx < 0 || ny < 0 || nx >= n || ny >= m) { printf("1\n"); return 0; } if (s[nx][ny] == '#' || vis[nx][ny] != -1) continue; vis[nx][ny] = vis[w.first][w.second] + 1; } } int ans = 999999; // cout << "???"<<endl; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (vis[i][j] == -1) continue; int dis = min(i, j); dis = min(dis, n - i - 1); dis = min(dis, m - j - 1); dis = dis / k + (dis % k != 0); ans = min(ans, 1 + dis); } } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:31:5: error: 'memset' was not declared in this scope 31 | memset(vis, -1, sizeof(vis)); | ^~~~~~ a.cc:19:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 18 | #include <utility> +++ |+#include <cstring> 19 | #include <vector>
s330373510
p03725
C++
#include <bits/stdc++.h> using namespace std; typedef int ll; #define int long long #define ff first #define ss second #define pb push_back #define mp make_pair #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() typedef pair<int,int>pii; typedef pair<int,pair<int,int> > piii; const int mod=1e9+7; int POWER[65]; int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;} int inv(int x) {return power(x,mod-2);} void precompute() { POWER[0]=1; for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL; } const int maxn=855; int sr=-1,sc=-1; bool vis[maxn][maxn]; int h,w,k,dis=100000000; vector<string>v; queue<int>xq,yq,le; bool chk(int x , int y , int z) { if(x>=0 && x<h && y>=0 && y<w) { if(vis[x][y]==0 && v[x][y]!='#') { vis[x][y]=1; int d=min(min(x,h-x-1),min(y,w-y-1)); dis=min(dis,d); if(z<=k) { xq.push(x); yq.push(y); le.push(z); } return 1; } } return 0; } void bfs(int i , int j) { chk(i,j,0); while (!xq.empty()) { int a=xq.front(),b=yq.front(),c=le.front(); chk(a-1,b,c+1); chk(a+1,b,c+1); chk(a,b-1,c+1); chk(a,b+1,c+1); xq.pop(),yq.pop(),le.pop(); } } ll main() { // freopen("Task.in","r",stdin);freopen("Task.out","w",stdout); std:ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>h>>w>>k; for (int i=0 ; i<h ; i++) { string s; cin>>s; v.pb(s); } for (int i=0 ; i<v.size() ; i++) { for (int j=0 ; j<v[i].size() ; j++) { if(v[i][j]=='S') { sr=i,sc=j; } } } bfs(sr,sc); int ans=dis/k+1; int d=min(min(sr,h-sr-1),min(sc,w-sc-1)); int ans2=d/k; if(d%k!=0) ans2++; if(dis%k!=0) ans++; ans=min(ans,ans2) cout<<ans<<endl; }
a.cc: In function 'll main()': a.cc:94:26: error: expected ';' before 'cout' 94 | ans=min(ans,ans2) | ^ | ; 95 | cout<<ans<<endl; | ~~~~
s450459221
p03725
C++
#include <cstdio> #include <cstdlib> #include <cmath> #include <iostream> #include <vector> #include <list> #include <algorithm> #include <functional> #include <map> #include <set> #include <cstring> #include <string> #include <cctype> #include <cassert> #include <stack> using namespace std; #define pb push_back #define mp make_pair #define rep(i,n) for(int i = 0; i < (n); i++) #define repr(i,b,e) for(int i = (b); i <= (e); i++) #define INF (1001001001) #define EPS (1e-15) #define pr(x) do{cout << (#x) << " = " << (x) << endl;}while(0) #define pri(x,i) do{cout << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0) #define pra(x,n) rep(__i,n) pri(x,__i); #define prar(x,b,e) repr(__i,b,e) pri(x,__i); typedef long long llint; typedef pair<int, int> pint; typedef vector<int> vint; int in() { int a; scanf("%d ", &a); return a; } vint v; int H, W; int K; int magic(int i, int k) { int ydist = min(i - 1, H - i); int xdist = min(k - 1, W - k); int dist = min(ydist, xdist); return (dist + K - 1) / K; } int main() { H = in(); W = in(); K = in(); vector<vint> v(810, vint(810, 0)); for (int i = 0; i < H + 2; i++) v[i][0] = v[i][W + 1] = -1; for (int i = 0; i < W + 2; i++) v[0][i] = v[H + 1][i] = -1; int y = -1, x = -1; for (int i = 1; i <= H; i++) { char temp[810]; gets(temp); for (int k = 1; k <= W; k++) { char c = temp[k - 1]; if (c == 'S') { y = i; x = k; } else if (c == '#') { // solid v[i][k] = 99; } } } assert(y >= 0 && x >= 0); int ans = magic(y, x); stack<pint> st; st.push(mp(y,x)); for (int i = 0; i < K + 1; i++) { stack<pint> st2; while (! st.empty()) { pint p = st.top(); st.pop(); v[p.first][p.second] = 1; ans = min(ans, magic(p.first, p.second)); for (int dy = -1; dy <= 1; dy++) { for (int dx = -1; dx <= 1; dx++) { if (dy * dx == 0 && v[p.first + dy][p.second + dx] == 0) { st2.push(mp(p.first + dy, p.second + dx)); } } } } st = st2; } cout << ans + 1 << endl; return 0; }
a.cc: In function 'int main()': a.cc:62:17: error: 'gets' was not declared in this scope; did you mean 'getw'? 62 | gets(temp); | ^~~~ | getw
s420090699
p03725
C++
#include<string> #include<iostream> #include<cstdio> #include<vector> #include<algorithm> #include<functional> using namespace std; typedef long long int llint; #define pub push_back #define mp make_pair #define fir first #define sec second #define res resize #define mt make_tuple const int big=((int)1<<30); int main(void){ int H,W,K,i,j,n,sx,sy,x,y,ka,sai=big; queue<tuple<int,int,int>> que;//x,y,回数 vector<string> hey; vector<vector<bool>>ot; cin>>H>>W>>K; hey.resize(H); ot.resize(H); for(i=0;i<H;i++){cin>>hey[i];} for(i=0;i<H;i++){ ot[i].resize(W); for(j=0;j<W;j++){ if(hey[i][j]=='S'){ sx=i;sy=j; } } } que.push(mt(sx,sy,K)); while(!que.empty()){ x=get<0>(que.front()); y=get<1>(que.front()); ka=get<2>(que.front()); que.pop(); if(ka==-1){break;} if(ot[x][y]){ ot[x][y]=true;continue; } sai=min(sai,min(min(x,H-x-1),min(y,W-y-1))); if(sai==0){ break; } if(hey[x+1][y]!='#'){que.push(mt(x+1,y,ka-1));} if(hey[x-1][y]!='#'){que.push(mt(x-1,y,ka-1));} if(hey[x][y+1]!='#'){que.push(mt(x,y+1,ka-1));} if(hey[x][y-1]!='#'){que.push(mt(x,y-1,ka-1));} } cout<<(sai+K-1)/K+1<<endl; return 0; }
a.cc: In function 'int main()': a.cc:18:9: error: 'queue' was not declared in this scope 18 | queue<tuple<int,int,int>> que;//x,y,回数 | ^~~~~ a.cc:7:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>' 6 | #include<functional> +++ |+#include <queue> 7 | using namespace std; a.cc:18:32: error: expected primary-expression before '>' token 18 | queue<tuple<int,int,int>> que;//x,y,回数 | ^~ a.cc:18:35: error: 'que' was not declared in this scope 18 | queue<tuple<int,int,int>> que;//x,y,回数 | ^~~
s629242392
p03726
C++
#include<bits/stdc++.h> #define ll long long #define ljc 998244353 using namespace std; #define gc getchar inline ll read(){ register ll x=0,f=1;char ch=gc(); while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();} while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();} return (f==1)?x:-x; } int head[1010101],tot,b[1010101]; struct edge{ int to,nxt; }g[1010011]; inline void made(int from,int to){ g[++tot].to=to;g[tot].nxt=head[from];head[from]=tot; } int n,indo[1010101]; signed main(){ n=read(); if (n&1){ printf("First");return 0; } return 1; for (int i=1;i<n;i++){ int x=read(),y=read(); made(x,y),made(y,x); } if (ans!=n/2){ } // for (int i=1;i<=n;i++){ // for (int j=head[i];j;j=g[j].nxt){ // int v=g[j].to; // if (indo[v]==1) b[i]++; // } // if (b[i]>=2){ // puts("First");return 0; // } // if (indo[i]>=3){ // puts("First");return 0; // } // } // puts("Second"); return 0; }
a.cc: In function 'long long int read()': a.cc:7:17: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 7 | register ll x=0,f=1;char ch=gc(); | ^ a.cc:7:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 7 | register ll x=0,f=1;char ch=gc(); | ^ a.cc: In function 'int main()': a.cc:30:13: error: 'ans' was not declared in this scope; did you mean 'abs'? 30 | if (ans!=n/2){ | ^~~ | abs
s187001903
p03726
C
#include<bits/stdc++.h> using namespace std; const int MAXN=1e5+7; struct side { int from,to,nex; }edge[MAXN<<1]; int head[MAXN],cntm=0; void link(int from,int to) { edge[++cntm].from=from; edge[cntm].to=to; edge[cntm].nex=head[from]; head[from]=cntm; } int n; int col[MAXN],siz[MAXN]; int ans=0; void dfs(int now,int fa) { siz[now]=1; for(int i=head[now];i;i=edge[i].nex) { if(edge[i].to!=fa) { dfs(edge[i].to,now); siz[now]+=siz[edge[i].to]; } } if(siz[now]==1) return; int cnt=0; for(int i=head[now],v;i;i=edge[i].nex) { v=edge[i].to; if(v==fa) continue; if(!col[v]) cnt++; } if(cnt==1) col[now]=1; if(cnt>1) ans=1; if(now==1&&cnt==0) ans=1; } int main() { cin>>n; for(int i=1,i1,i2;i<n;i++) { cin>>i1>>i2; link(i1,i2); link(i2,i1); } dfs(1,0); if(ans) cout<<"First"<<endl; else cout<<"Second"<<endl; }
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory 1 | #include<bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s024630360
p03726
C++
// -------------------------------------------- // **************** gzhffIThh *************** // -------------------------------------------- // #pragma GCC optimize(2) // #pragma GCC optimize(3) #include <iostream> #include <cstdio> #include <queue> #include <vector> #include <cstring> #include <algorithm> using namespace std; const int N = 100010; int head[N], nxt[N << 1], v[N << 1], cnt, size[N]; void add(int x, int y) { nxt[++cnt] = head[x]; head[x] = cnt; v[cnt] = y; } bool fl = 0; void dfs(int now, int fa) { int su = 0; size[now] = 1; for (int i = head[now]; i; i = nxt[i]) { if (v[i] == fa) continue; dfs(v[i], now); su += size[v[i]]; size[now] ^= size[v[i]]; } if (su >= 2) { fl = 1; } } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n & 1) { cout << "First\n"; return 0; } for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; add(x, y); add(y, x); } dfs(1, 0); if (fl) { cout << "First\n"; } else { cout << "Second\n"; } return 0; }
a.cc: In function 'void dfs(int, int)': a.cc:28:9: error: reference to 'size' is ambiguous 28 | size[now] = 1; | ^~~~ In file included from /usr/include/c++/14/string:53, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:7: /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:18:43: note: 'int size [100010]' 18 | int head[N], nxt[N << 1], v[N << 1], cnt, size[N]; | ^~~~ a.cc:32:23: error: reference to 'size' is ambiguous 32 | su += size[v[i]]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:18:43: note: 'int size [100010]' 18 | int head[N], nxt[N << 1], v[N << 1], cnt, size[N]; | ^~~~ a.cc:33:17: error: reference to 'size' is ambiguous 33 | size[now] ^= size[v[i]]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:18:43: note: 'int size [100010]' 18 | int head[N], nxt[N << 1], v[N << 1], cnt, size[N]; | ^~~~ a.cc:33:30: error: reference to 'size' is ambiguous 33 | size[now] ^= size[v[i]]; | ^~~~ /usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])' 272 | size(const _Tp (&)[_Nm]) noexcept | ^~~~ /usr/include/c++/14/bits/range_access.h:262:5: note: 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)' 262 | size(const _Container& __cont) noexcept(noexcept(__cont.size())) | ^~~~ a.cc:18:43: note: 'int size [100010]' 18 | int head[N], nxt[N << 1], v[N << 1], cnt, size[N]; | ^~~~
s692178471
p03726
C
#include <bits/stdc++.h> using namespace std; const int maxn = 100 * 1000 + 10; int n; vector <int> adj[maxn]; bool ans, leaf[maxn]; void dfs(int v, int papa) { if (ans) return; int o = 0, tmp = 0; bool f = 1; for (int u: adj[v]) if (u != papa) { dfs(u, v); o += (leaf[u]); f = 0; } if (f) leaf[v] = 1; if (o > 1) ans = 1; } int main() { cin >> n; for (int i = 0, a, b; i < n - 1; i++) { cin >> a >> b; adj[--a].push_back(--b); adj[b].push_back(a); } dfs(0, -1); cout << (((n % 2) || ans)? "First\n": "Second\n"); return 0; }
main.c:1:10: fatal error: bits/stdc++.h: No such file or directory 1 | #include <bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s267329062
p03726
C++
de<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" const int N = 1e5 + 10; int n; vector <int> adj[N]; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); } bool is = false; for (int i = 0; i < n; i++) { int cnt = 0; for (auto x: adj[i]) if (adj[x].size() == 1) cnt++; if (cnt >= 2) { is = true; break; } } if (is) cout << "First"; else cout << "Second"; }
a.cc:1:1: error: 'de' does not name a type 1 | de<bits/stdc++.h> | ^~ a.cc:9:1: error: 'vector' does not name a type 9 | vector <int> adj[N]; | ^~~~~~ a.cc: In function 'int main()': a.cc:12:9: error: 'cin' was not declared in this scope 12 | cin >> n; | ^~~ a.cc:17:17: error: 'adj' was not declared in this scope 17 | adj[u].push_back(v); | ^~~ a.cc:23:30: error: 'adj' was not declared in this scope 23 | for (auto x: adj[i]) | ^~~ a.cc:32:17: error: 'cout' was not declared in this scope 32 | cout << "First"; | ^~~~ a.cc:34:17: error: 'cout' was not declared in this scope 34 | cout << "Second"; | ^~~~
s185294615
p03726
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define endl "\n" const int N = 1e5 + 10; int n; vector <int> adj[N]; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; adj[u].push_back(v); adj[v].push_back(u); } bool is = false; for (int i = 0; i < n; i++) { int cnt = 0; for (auto x: adj[i]) if (adj[x].size() == 1) cnt++; if (cnt >= 2) { is = true; break; } } if (is) cout << "First"; else cout << "Second"; } ~ ~ ~ ~
a.cc:37:1: error: expected class-name before '~' token 37 | ~ | ^
s141471336
p03726
C++
#include <bits/stdc++.h> #define N 100034 #define M 256101 using namespace std; int n, e; int u, v, i; int to[M], first[N], next[M]; inline void addedge(int u, int v){ to[++e] = v; next[e] = first[u]; first[u] = e; to[++e] = u; next[e] = first[v]; first[v] = e; } int dfs(int x, int px){ int i, y, scx = 0; for(i = first[x]; i; i = next[i]) if((y = to[i]) != px) if((scx += dfs(y, x)) >= 2) return 2; return !scx; } int main(){ scanf("%d", &n); for(i = 1; i < n; ++i){ scanf("%d%d", &u, &v); addedge(u, v); } puts(dfs(1, 0) ? "First" : "Second"); return 0; }
a.cc: In function 'void addedge(int, int)': a.cc:11:18: error: reference to 'next' is ambiguous 11 | to[++e] = v; next[e] = first[u]; first[u] = e; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:8:22: note: 'int next [256101]' 8 | int to[M], first[N], next[M]; | ^~~~ a.cc:12:18: error: reference to 'next' is ambiguous 12 | to[++e] = u; next[e] = first[v]; first[v] = e; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:8:22: note: 'int next [256101]' 8 | int to[M], first[N], next[M]; | ^~~~ a.cc: In function 'int dfs(int, int)': a.cc:17:30: error: reference to 'next' is ambiguous 17 | for(i = first[x]; i; i = next[i]) | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:8:22: note: 'int next [256101]' 8 | int to[M], first[N], next[M]; | ^~~~
s305282963
p03726
C++
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; typedef long long ll; vector<ll> node[100005]; bool matched[100005],used[100005]; void dfs(ll pos){ for(int i=0;i<node[pos].size();i++){ ll son=node[pos][i]; if(!used[to]){ used[to]=true; dfs(to); if(!matched[pos]&&!matched[son]){ matched[pos]=true; matched[son]=true; } } } } int main(){ ll n; cin>>n; for(int i=1;i<n;i++){ ll s,t; cin>>s>>t; node[s].push_back(t); node[t].push_back(s); } for(int i=1;i<=n;i++) { used[i]=false; matched[i]=false; } used[1]=true; dfs(1); for(int i=1;i<=n;i++){ if(!matched[i]){ cout<<"Second"<<endl; return 0; } } cout<<"First"<<endl; return 0; }
a.cc: In function 'void dfs(ll)': a.cc:12:14: error: 'to' was not declared in this scope; did you mean 'tm'? 12 | if(!used[to]){ | ^~ | tm
s060723184
p03726
C++
//#undef _DEBUG //#pragma GCC optimize("Ofast") //不動小数点の計算高速化 //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace std::chrono; #define int long long //todo 消したら動かない intの代わりにsignedを使う #define ll long long auto start_time = system_clock::now(); auto past_time = system_clock::now(); #define debugName(VariableName) # VariableName //最大引数がN #define over2(o1, o2, name, ...) name #define over3(o1, o2, o3, name, ...) name #define over4(o1, o2, o3, o4, name, ...) name #define over5(o1, o2, o3, o4, o5, name, ...) name #define over6(o1, o2, o3, o4, o5, o6, name, ...) name #define over7(o1, o2, o3, o4, o5, o6, o7, name, ...) name #define over8(o1, o2, o3, o4, o5, o6, o7, o8, name, ...) name #define over9(o1, o2, o3, o4, o5, o6, o7, o8, o9, name, ...) name #define over10(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name /*@formatter:off*/ //[-n, n)にアクセスできる //また、外部関数resizeに渡せる //sizeは[-n, n)でnを返す template<class T> class mvec { vector<T> v; int n;public: mvec() : n(0), v(0) {} mvec(int n) : n(n), v(n * 2) {} mvec(int n, T val) : n(n), v(n * 2, val) {} auto &operator[](int i) { return v[i + n]; } auto size() { return n; } void resize(int sn) { assert(n == 0); n = sn; v.resize(sn * 2); } auto begin() { return v.begin(); } auto rbegin() { return v.rbegin(); } auto end() { return v.end(); } auto rend() { return v.rend(); }}; //[]でboolは参照を返さないため特殊化が必要 template<> struct mvec<bool> { vector<bool> v; int n; mvec() : n(0), v(0) {} mvec(int n) : n(n), v(n * 2) {} mvec(int n, bool val) : n(n), v(n * 2, val) {} auto operator[](int i) { return v[i + n]; } auto size() { return v.size(); } void resize(int sn) { assert(n == 0); n = sn; v.resize(sn * 2); } auto begin() { return v.begin(); } auto rbegin() { return v.rbegin(); } auto end() { return v.end(); } auto rend() { return v.rend(); }}; template<class T>ostream &operator<<(ostream &os, mvec<T>& a) { int spa = 3; for(auto&&v : a){ spa = max(spa,(int)(to_string(v).size())+1); } int n = (int)a.size(); os<<endl; for (int i = -n; i < n; i++){ int need = spa - ((int)to_string(i).size()); if(i==-n){ need -= min(need,spa - ((int)to_string(a[i]).size())); } while(need--){ os<<" "; } os<<i; } os<<endl; int i=-n; for(auto&&v : a){ int need = spa - ((int)to_string(v).size()); if(i==-n){ need -= min(need,spa - ((int)to_string(i).size())); } while(need--){ os<<" "; } os<<v; i++; } return os;} #define mv mvec #define MV mvec using mvi = mvec<ll>; using mvb = mvec<bool>; using mvs = mvec<string>; using mvd = mvec<double>; using mvc = mvec<char>; #define mvvt0(t) mvec<mvec<t>> #define mvvt1(t,a) mvec<mvec<t>>a #define mvvt2(t,a, b) mvec<mvec<t>>a(b) #define mvvt3(t,a, b, c) mvec<mvec<t>> a(b,mvec<t>(c)) #define mvvt4(t,a, b, c, d) mvec<mvec<t>> a(b,mvec<t>(c,d)) #define mvvi(...) over4(__VA_ARGS__,mvvt4,mvvt3,mvvt2 ,mvvt1,mvvt0)(ll,__VA_ARGS__) template<typename T> mvec<T> make_mv(size_t a) { return mvec<T>(a); } template<typename T, typename... Ts> auto make_mv(size_t a, Ts... ts) {return mvec<decltype(make_mv<T>(ts...))>(a, make_mv<T>(ts...));} #define mvni(name, ...) auto name = make_mv<ll>(__VA_ARGS__) #ifdef _DEBUG string message; //https://marycore.jp/prog/cpp/class-extension-methods/ 違うかも template<class T, class A = std::allocator<T>> struct debtor : std::vector<T, A> { using std::vector<T, A>::vector; template<class U> int deb_v(U a, int v) { return v; } template<class U> int deb_v(debtor<U> &a, int v = 0) {cerr << a.size() << " ";return deb_v(a.at(0), v + 1);} template<class U> void deb_o(U a) { cerr << a << " "; } template<class U> void deb_o(debtor<U> &a) {for (int i = 0; i < min((int) a.size(), 15ll); i++) { deb_o(a[i]); }if ((int) a.size() > 15) { cerr << "..."; }cerr << endl;} typename std::vector<T>::reference operator[](typename std::vector<T>::size_type n) { if (n < 0 || n >= (int) this->size()) { int siz = (int) this->size(); cerr << "vector size = "; int dim = deb_v((*this)); cerr << endl; cerr << "out index at " << n << endl; cerr << endl; if (dim <= 2) { deb_o((*this)); } exit(0); }return this->at(n);} }; //#define vector debtor //区間削除は出来ない template<class T> struct my_pbds_tree { set<T> s; auto begin() { return s.begin(); } auto end() { return s.end(); } auto rbegin() { return s.rbegin(); } auto rend() { return s.rend(); } auto empty() { return s.empty(); } auto size() { return s.size(); } void clear() { s.clear(); } template<class U> void insert(U v) { s.insert(v); }template<class U> void operator+=(U v) { insert(v); } template<class F> auto erase(F v) { return s.erase(v); } template<class U> auto find(U v) { return s.find(v); } template<class U> auto lower_bound(U v) { return s.lower_bound(v); } template<class U> auto upper_bound(U v) { return s.upper_bound(v); } auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; } auto order_of_key(ll v) { auto it = s.begin(); ll i=0; for (;it != s.end() && *it <v ; i++)it++; return i; }}; #define pbds(T) my_pbds_tree<T> //gp_hash_tableでcountを使えないようにするため template<class T,class U> struct my_unordered_map{ unordered_map<T,U> m; my_unordered_map(){}; auto begin(){ return m.begin(); } auto end(){return m.end();} auto cbegin(){return m.cbegin();} auto cend(){return m.cend();} template<class V>auto erase(V v){return m.erase(v);} void clear(){m.clear();} /*countは gp_hash_tableに存在しない*/ /*!= m.end()*/ template<class V>auto find(V v){return m.find(v);} template<class V>auto & operator [](V n) { return m[n] ;}}; #define unordered_map my_unordered_map #define umapi unordered_map<ll,ll> #define umapp unordered_map<P,ll> #define umapu unordered_map<uint64_t,ll> #define umapip unordered_map<ll,P> #else #define endl '\n' //umapはunorderd_mapになる //umapiはgp_hash_table //find_by_order(k) k番目のイテレーター //order_of_key(k) k以上が前から何番目か #define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> #define umapi __gnu_pbds::gp_hash_table<ll,ll,xorshift> #define umapp __gnu_pbds::gp_hash_table<P,ll,xorshift> #define umapu __gnu_pbds::gp_hash_table<uint64_t,ll,xorshift> #define umapip __gnu_pbds::gp_hash_table<ll,P,xorshift> #endif /*@formatter:on*/ struct xorshift { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } size_t operator()(std::pair<ll, ll> x) const { ll v = ((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); } }; /*@formatter:off*/ template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); } //衝突対策 #define ws ws_ template<class A, class B, class C>struct T2 {A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }}; template<class A, class B, class C, class D> struct F2 { A a; B b; C c; D d; F2() { a = 0, b = 0, c = 0, d = 0; } F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {} bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ } bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ } bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; } bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; } ll operator[](ll i) { assert(i < 4); return i == 0 ? a : i == 1 ? b : i == 2 ? c : d; }}; typedef T2<ll, ll, ll> T; typedef F2<ll, ll, ll, ll> F; T mt(ll a, ll b, ll c) {return T(a, b, c);} F mf(ll a, ll b, ll c, ll d) {return F(a, b, c, d);} //@マクロ省略系 型,構造 #define double long double using dou = double; const double eps = 1e-9; //基本コメントアウト /* struct epsdou { double v; epsdou(double v = 0) : v(v) {} template<class T> epsdou &operator+=(T b) { v += (double) b; return (*this); } template<class T> epsdou &operator-=(T b) { v -= (double) b; return (*this); } template<class T> epsdou &operator*=(T b) { v *= (double) b; return (*this); } template<class T> epsdou &operator/=(T b) { v /= (double) b; return (*this); } epsdou operator+(epsdou b) { return v + (double) b; } epsdou operator-(epsdou b) { return v - (double) b; } epsdou operator*(epsdou b) { return v * (double) b; } epsdou operator/(epsdou b) { return v / (double) b; } epsdou operator-() const { return epsdou(-v); } template<class T> bool operator<(T b) { return v < (double) b; } template<class T> bool operator>(T b) { return v > (double) b; } template<class T> bool operator==(T b) { return fabs(v - (double) b) <= eps; } template<class T> bool operator<=(T b) { return v < (double) b || fabs(v - b) <= eps; } template<class T> bool operator>=(T b) { return v > (double) b || fabs(v - b) <= eps; } operator double() { return v; }};istream &operator>>(istream &iss, epsdou &a) { iss >> a.v; return iss;}ostream &operator<<(ostream &os, epsdou &a) { os << a.v; return os;} #define eps_conr_t(o) template<class T> epsdou operator o(T b, epsdou a){return a.v o (dou)b;} #define eps_conl_t(o) template<class T> epsdou operator o(epsdou a, T b){return a.v o (dou)b;} eps_conl_t(+)eps_conl_t(-)eps_conl_t(*)eps_conl_t(/)eps_conr_t(+)eps_conr_t(-)eps_conr_t(*)eps_conr_t(/) #undef double #define double epsdou */ #define ull unsigned long long using itn = int; using str = string; using bo= bool; #define au auto using P = pair<ll, ll>; using mvp = mvec<P>; using mvt = mvec<T>; #define MIN(a) numeric_limits<a>::min() #define MAX(a) numeric_limits<a>::max() #define fi first #define se second #define beg begin #define rbeg rbegin #define con continue #define bre break #define brk break #define is == #define el else #define elf else if #define upd update #define sstream stringstream #define maxq 1 #define minq -1 #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MALLOC(type, len) (type*)malloc((len) * sizeof(type)) #define lam1(ret) [&](auto& v){return ret;} #define lam2(v, ret) [&](auto& v){return ret;} #define lam(...) over2(__VA_ARGS__,lam2,lam1)(__VA_ARGS__) #define lamr(right) [&](auto& p){return p right;} //マクロ省略系 コンテナ using vi = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vd = vector<double>; using vc = vector<char>; using vp = vector<P>; using vt = vector<T>; //#define V vector #define vvt0(t) vector<vector<t>> #define vvt1(t,a) vector<vector<t>>a #define vvt2(t,a, b) vector<vector<t>>a(b) #define vvt3(t,a, b, c) vector<vector<t>> a(b,vector<t>(c)) #define vvt4(t,a, b, c, d) vector<vector<t>> a(b,vector<t>(c,d)) #define vvi(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__) #define vvb(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__) #define vvs(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__) #define vvd(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__) #define vvc(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__) #define vvp(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__) #define vvt(...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__) #define vv(type,...) over4(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(type,__VA_ARGS__) template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));} #define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__) #define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__) #define vns(name, ...) auto name = make_v<string>(__VA_ARGS__) #define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__) #define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__) #define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__) #define vn(type,name, ...) auto name = make_v<type>(__VA_ARGS__) #define PQ priority_queue<ll, vector<ll>, greater<ll> > #define tos to_string using mapi = map<ll, ll>; using mapp = map<P, ll>; using mapd = map<dou, ll>; using mapc = map<char, ll>; using maps = map<str, ll>; using seti = set<ll>; using setp = set<P>; using setd = set<dou>; using setc = set<char>; using sets = set<str>; using qui = queue<ll>; #define uset unordered_set #define useti unordered_set<ll,xorshift> #define mset multiset #define mseti multiset<ll> #define umap unordered_map #define mmap multimap //任意のマクロサポート用 使う度に初期化する int index_,v1_,v2_,v3_; template<class T> struct pq { priority_queue<T, vector<T>, greater<T> > q;/*小さい順*/ T su = 0; void clear() { q = priority_queue<T, vector<T>, greater<T> >(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); } }; template<class T> struct pqg { priority_queue<T> q;/*大きい順*/ T su = 0; void clear() { q = priority_queue<T>(); su = 0; } void operator+=(T v) { su += v; q.push(v); } T sum() { return su; } T top() { return q.top(); } void pop() { su -= q.top(); q.pop(); } T poll() { T ret = q.top(); su -= ret; q.pop(); return ret; } ll size() { return q.size(); } }; #define pqi pq<ll> #define pqgi pqg<ll> //マクロ 繰り返し //↓@オーバーロード隔離 #define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i) #define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i) #define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i) #define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad) //逆順 閉区間 #define rer2(i, n) for(ll i = n; i >= 0 ; i--) #define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--) #define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec) //ループを一つにまとめないとフォーマットで汚くなるため #define nex_ind1(i) i++ #define nex_ind2(i, j, J) i = (j + 1 == J) ? i + 1 : i, j = (j + 1 == J ? 0 : j + 1) #define nex_ind3(i, j, k, J, K)i = (j + 1 == J && k + 1 == K) ? i + 1 : i, j = (k + 1 == K) ? (j + 1 == J ? 0 : j + 1) : j, k = (k + 1 == K ? 0 : k + 1) #define nex_ind4(i, j, k, l, J, K, L) i = (j + 1 == J && k + 1 == K && l + 1 == L) ? i + 1 : i, j = (k + 1 == K && l + 1 == L) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L ?(k + 1 == K ? 0 : k + 1) : k), l = l + 1 == L ? 0 : l + 1 #define nex_ind5(i, j, k, l, m, J, K, L, M) i = (j + 1 == J && k + 1 == K && l + 1 == L && m + 1 == M) ? i + 1 : i, j = (k + 1 == K && l + 1 == L && m + 1 == M) ? (j + 1 == J ? 0 : j + 1) : j, k = (l + 1 == L && m + 1 == M ?(k + 1 == K ? 0 : k + 1) : k), l = m + 1 == M ? l+1 == L ? 0 : l+1 : l, m = m + 1 == M ? 0 : m + 1 #define repss2(i, I) for (int i = 0; i < I; i++) #define repss4(i, j, I, J) for (int i = (J ? 0 : I), j = 0; i < I; nex_ind2(i, j, J)) #define repss6(i, j, k, I, J, K) for (int i = (J && K ? 0 : I), j = 0, k = 0; i < I; nex_ind3(i, j, k, J, K)) #define repss8(i, j, k, l, I, J, K, L) for (int i = (J && K && L ? 0 : I), j = 0, k = 0, l = 0; i < I; nex_ind4(i, j, k, l, J, K, L)) #define repss10(i, j, k, l, m, I, J, K, L, M)for (int i = (J && K && L && M ? 0 : I), j = 0, k = 0, l = 0, m = 0; i < I; nex_ind5(i, j, k, l, m, J, K, L, M)) //i,j,k...をnまで見る #define reps2(i, n) repss2(i, n) #define reps3(i, j, n) repss4(i, j, n, n) #define reps4(i, j, k, n) repss6(i, j, k, n, n, n) #define reps5(i, j, k, l, n) repss8(i, j, k, l, n, n, n, n) template<class T>void nex_repv2(int&i,int&j,int&I, int&J,vector<vector<T>>&s){ while(1){ j++; if(j >= J){ j=0; i++; if(i < I){ J = (int)s[i].size(); } } if(i >= I || J) return; }} template<class T> void nex_repv3(int &i, int &j, int &k, int &I, int &J, int &K, vector<vector<vector<T>>> &s) { while (1) { k++; if (k >= K) { k = 0; j++; if (j >= J) { j = 0; i++; if (i >= I)return; } } J = (int) s[i].size(); K = (int) s[i][j].size(); if (J && K) return; }} #define repv_2(i,a) repss2(i, sz(a)) //正方形である必要はない //直前を持つのとどっちが早いか #define repv_3(i, j, a) for (int I = (int)a.size(), J = (int)a[0].size(), i = 0, j = 0; i < I; nex_repv2(i,j,I,J,a)) //箱状になっている事が要求される つまり[i] 次元目の要素数は一定 #define repv_4(i, j, k, a) for (int I = (int)a.size(), J = (int)a[0].size(), K =(int)a[0][0].size(), i = 0, j = 0, k=0; i < I; nex_repv3(i,j,k,I,J,K,a)) #define repv_5(i, j, k, l, a) repss8(i, j, k, l, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0])) #define repv_6(i, j, k, l, m, a) repss10(i, j, k, l, m, sz(a), sz(a[0]), sz(a[0][0]), sz(a[0][0][0]), sz(a[0][0][0][0])) template<typename T>struct has_rbegin_rend {private:template<typename U>static auto check(U &&obj) -> decltype(std::rbegin(obj), std::rend(obj), std::true_type{});static std::false_type check(...);public:static constexpr bool value = decltype(check(std::declval<T>()))::value;};template<typename T>constexpr bool has_rbegin_rend_v = has_rbegin_rend<T>::value;template<typename Iterator>class Range {public:Range(Iterator &&begin, Iterator &&end) noexcept: m_begin(std::forward<Iterator>(begin)), m_end(std::forward<Iterator>(end)) {}Iterator begin() const noexcept {return m_begin;}Iterator end() const noexcept {return m_end;}private:const Iterator m_begin;const Iterator m_end;};template<typename Iterator>static inline Range<Iterator>makeRange(Iterator &&begin, Iterator &&end) noexcept {return Range<Iterator>{std::forward<Iterator>(begin), std::forward<Iterator>(end)};}template<typename T>static inline decltype(auto) makeReversedRange(const std::initializer_list<T> &iniList) noexcept {return makeRange(std::rbegin(iniList), std::rend(iniList));}template<typename T,typename std::enable_if_t<has_rbegin_rend_v<T>, std::nullptr_t> = nullptr>static inline decltype(auto)makeReversedRange(T &&c) noexcept {return makeRange(std::rbegin(c), std::rend(c));}/* rbegin(), rend()を持たないものはこっちに分岐させて,エラーメッセージを少なくする*/template<typename T,typename std::enable_if<!has_rbegin_rend<T>::value, std::nullptr_t>::type = nullptr>static inline void makeReversedRange(T &&) noexcept {static_assert(has_rbegin_rend<T>::value, "Specified argument doesn't have reverse iterator.");} #define form1(st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it) #define form3(k, v, st) for (auto &&form_it = st.begin(); form_it != st.end(); ++form_it) #define form4(k, v, st, r) for (auto &&form_it = st.begin(); form_it != st.end() && (*form_it).fi < r; ++form_it) #define form5(k, v, st, l, r) for (auto &&form_it = st.lower_bound(l); form_it != st.end() && (*form_it).fi < r; ++form_it) #define forrm1(st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it) #define forrm3(k, v, st) for (auto &&forrm_it = st.rbegin(); forrm_it != st.rend(); ++forrm_it) #define fors1(st) for (auto &&fors_it = st.begin(); fors_it != st.end(); ++fors_it) #define fors2(v, st) for (auto &&fors_it = st.begin(); fors_it != st.end(); ++fors_it) #define fors3(v, st, r) for (auto &&fors_it = st.begin(); fors_it != st.end() && (*fors_it) < r; ++fors_it) #define fors4(v, st, l, r) for (auto &&fors_it = st.lower_bound(l); fors_it != st.end() && (*fors_it) < r; ++fors_it) #define forslr3(st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it) #define forslr4(v, st, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end(); ++forslr_it) #define forslr5(v, st, r, a, b) for (auto &&forslr_it = st.begin(); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it) #define forslr6(v, st, l, r, a, b) for (auto &&forslr_it = st.lower_bound(l); forslr_it != st.end() && (*forslr_it) < r; ++forslr_it) template<class U> vector<U>to1d(vector<U>& a){return a;} template<class U> vector<U>to1d(vector<vector<U>>&a){vector<U> res;for(auto&& a1 : a)for(auto&& a2 : a1)res.push_back(a2);return res;} template<class U> vector<U>to1d(vector<vector<vector<U>>>&a){vector<U> res;for(auto&& a1 : a)for(auto&& a2 : a1)for(auto&& a3 : a2) res.push_back(a3);return res;} template<class U> vector<U>to1d(vector<vector<vector<vector<U>>>>&a){vector<U> res;for(auto&& a1 : a)for(auto&& a2 : a1)for(auto&& a3 : a2) for(auto&& a4 : a3)res.push_back(a4);return res;} template<class U> vector<U>to1d(vector<vector<vector<vector<vector<U>>>>>&a){vector<U> res;for(auto&& a1 : a)for(auto&& a2 : a1)for(auto&& a3 : a2) for(auto&& a4 : a3)for(auto&& a5 : a4)res.push_back(a5);return res;} template<class U> vector<U>to1d(vector<vector<vector<vector<vector<vector<U>>>>>>&a){vector<U> res;for(auto&& a1 : a)for(auto&& a2 : a1)for(auto&& a3 : a2) for(auto&& a4 : a3)for(auto&& a5 : a4)for(auto&& a6 : a5)res.push_back(a6);return res;} #define fora_init_2(a, A) ; #define fora_init_3(fora_i, a, A) auto &&a = A[fora_i]; #define fora_init_4(a, b, A, B) auto &&a = A[fora_i]; auto &&b = B[fora_i]; #define fora_init_5(fora_i, a, b, A, B) auto &&a = A[fora_i]; auto &&b = B[fora_i]; #define fora_init_6(a, b, c, A, B, C) auto &&a = A[fora_i]; auto &&b = B[fora_i]; auto &&c = C[fora_i]; #define fora_init_7(fora_i, a, b, c, A, B, C) auto &&a = A[fora_i]; auto &&b = B[fora_i]; auto &&c = C[fora_i]; #define fora_init_8(a, b, c, d, A, B, C, D) auto &&a = A[fora_i]; auto &&b = B[fora_i]; auto &&c = C[fora_i]; auto && d = D[fora_i]; #define fora_init_9(fora_i, a, b, c, d, A, B, C, D) auto &&a = A[fora_i]; auto &&b = B[fora_i]; auto &&c = C[fora_i]; auto && d = D[fora_i]; #define fora_init(...) over9(__VA_ARGS__,fora_init_9, fora_init_8, fora_init_7, fora_init_6, fora_init_5, fora_init_4, fora_init_3, fora_init_2)(__VA_ARGS__) #define forr_init_2(a, A) auto &&a = A[forr_i]; #define forr_init_3(forr_i, a, A) auto &&a = A[forr_i]; #define forr_init_4(a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i]; #define forr_init_5(forr_i, a, b, A, B) auto &&a = A[forr_i]; auto &&b = B[forr_i]; #define forr_init_6(a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; #define forr_init_7(forr_i, a, b, c, A, B, C) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; #define forr_init_8(a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i]; #define forr_init_9(forr_i, a, b, c, d, A, B, C, D) auto &&a = A[forr_i]; auto &&b = B[forr_i]; auto &&c = C[forr_i]; auto && d = D[forr_i]; #define forr_init(...) over9(__VA_ARGS__, forr_init_9, forr_init_8, forr_init_7, forr_init_6, forr_init_5, forr_init_4, forr_init_3, forr_init_2)(__VA_ARGS__) #define forp_init(k, v, ...) auto &&k = (*forp_it).fi;auto &&v = (*forp_it).se; #define form_init(k, v, ...) auto &&k = (*form_it).fi;auto &&v = (*form_it).se; #define forrm_init(k, v, ...) auto &&k = (*forrm_it).fi;auto &&v = (*forrm_it).se; #define fors_init(v, ...) auto &&v = (*fors_it); #define forlr_init(a,A,ngl,ngr) auto a = A[forlr_i]; auto prev = forlr_i ? A[forlr_i-1] : ngl;auto next = forlr_i+1< rep2lim? A[forlr_i+1] : ngr; #define forslr_init4(a, A, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init5(a, A, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init6(a, A, l, r, ngl, ngr) auto a = (*forslr_it); auto prev = (forslr_it!=A.begin())? (*std::prev(forslr_it)) : ngl;auto next = (forslr_it!=std::prev(A.end()))? (*std::next(forslr_it)) : ngr; #define forslr_init(...) over6(__VA_ARGS__,forslr_init6,forslr_init5,forslr_init4)(__VA_ARGS__); #define fora_2(a, A) for(auto&& a : A) #define fora_3(fora_i, a, A) rep(fora_i, sz(A)) #define fora_4(a, b, A, B) rep(fora_i, sz(A)) #define fora_5(fora_i, a, b, A, B) rep(fora_i, sz(A)) #define fora_6(a, b, c, A, B, C) rep(fora_i, sz(A)) #define fora_7(fora_i, a, b, c, A, B, C) rep(fora_i, sz(A)) #define fora_8(a, b, c, d, A, B, C, D) rep(fora_i, sz(A)) #define fora_9(fora_i, a, b, c, d, A, B, C, D) rep(fora_i, sz(A)) #define forr_2(a, A) rer(forr_i, sz(A)-1) #define forr_3(forr_i, a, A) rer(forr_i, sz(A)-1) #define forr_4(a, b, A, B) rer(forr_i, sz(A)-1) #define forr_5(forr_i, a, b, A, B) rer(forr_i, sz(A)-1) #define forr_6(a, b, c, A, B, C) rer(forr_i, sz(A)-1) #define forr_7(forr_i, a, b, c, A, B, C) rer(forr_i, sz(A)-1) #define forr_8(a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1) #define forr_9(forr_i, a, b, c, d, A, B, C, D) rer(forr_i, sz(A)-1) //↑@オーバーロード隔離 //rep系はインデックス、for系は中身 #define rep(...) over4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rer(...) over4(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__) //char用のrep #define repc(i, m, n) for(char i = m,repc3lim=n; i < repc3lim ; ++i) //i,j,k...をnまで見る #define reps(...) over5(__VA_ARGS__,reps5,reps4,reps3,reps2,)(__VA_ARGS__) #define repss(...) over10(__VA_ARGS__, repss10, a, repss8, a, repss6, a, repss4, a, repss2) (__VA_ARGS__) //vectorのindexを走査する //repv(i,j,vvi) #define repv(...) over6(__VA_ARGS__,repv_6,repv_5,repv_4,repv_3,repv_2,)(__VA_ARGS__) #define rerv(i, A) for (int i = sz(A)-1; i >= 0 ; i--) //repvn(dp) nは次元 #define repv1(a) repv(i, a) #define repv2(a) repv(i, j, a) #define repv3(a) repv(i, j, k, a) #define repv4(a) repv(i, j, k, l, a) #define fora(...) over9(__VA_ARGS__, fora_9, fora_8, fora_7, fora_6, fora_5, fora_4, fora_3, fora_2)(__VA_ARGS__) #define forr(...) over9(__VA_ARGS__, forr_9, forr_8, forr_7, forr_6, forr_5, forr_4, forr_3, forr_2)(__VA_ARGS__) //#define forr(v, a) for(auto&& v : makeReversedRange(a)) //参照を取らない #define forv(a, b) for(auto a : to1d(b)) //インデックスを前後含めて走査 #define ring(i, s, len) for (int i = s, prev = (s == 0) ? len - 1 : s - 1, next = (s == len - 1) ? 0 : s + 1, cou = 0; cou < len; cou++, prev = i, i = next, next = (next == len - 1) ? 0 : next + 1) //値と前後を見る #define ringv(v, d) index_=0;for (auto prev = d[sz(d)-1],next= (int)d.size()>1?d[1]:d[0],v = d[0]; index_ < sz(d); index_++, prev = v, v = next, next = (index_>=sz(d)-1?d[0]:d[index_+1])) // 左右をnext prevで見る 0の左と nの右 #define forlr(v, d, banpei_l, banpei_r) rep(forlr_i,sz(d)) #define form(...) over5(__VA_ARGS__,form5,form4,form3,form2,form1)(__VA_ARGS__) #define forrm(...) over5(__VA_ARGS__,forrm5,forrm4,forrm3,forrm2,forrm1)(__VA_ARGS__) #define fors(...) over4(__VA_ARGS__,fors4,fors3,fors2,fors1)(__VA_ARGS__) #define forslr(...) over6(__VA_ARGS__,forslr6,forslr5,forslr4,forslr3)(__VA_ARGS__) #define forp(k, v, st) for (auto &&forp_it = st.begin(); forp_it != st.end(); ++forp_it) //マクロ 定数 #define k3 1010 #define k4 10101 #define k5 101010 #define k6 1010101 #define k7 10101010 const ll inf = (ll) 1e9 + 100; const ll linf = (ll) 1e18 + 100; const dou dinf = (dou) linf * linf; const char infc = '{'; const string infs = "{"; const double PI = 3.1415926535897932384626433832795029L; //マクロ省略形 関数等 #define arsz(a) (sizeof(a)/sizeof(a[0])) #define sz(a) ((ll)(a).size()) #define mp make_pair #define pb pop_back #define pf push_front #define eb emplace_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() constexpr bool ev(ll a) { return !(a & 1); } constexpr bool od(ll a) { return (a & 1); } //@拡張系 こう出来るべきというもの //埋め込み 存在を意識せずに機能を増やされているもの namespace std { template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; } //stream まとめ /*@formatter:on*/ istream &operator>>(istream &iss, P &a) { iss >> a.first >> a.second; return iss; } template<typename T> istream &operator>>(istream &iss, vector<T> &vec) { for (T &x: vec) iss >> x; return iss; } template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) { os << p.fi << " " << p.se; return os; } ostream &operator<<(ostream &os, T p) { os << p.f << " " << p.s << " " << p.t; return os; } ostream &operator<<(ostream &os, F p) { os << p.a << " " << p.b << " " << p.c << " " << p.d; return os; } template<typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (ll i = 0; i < vec.size(); ++i)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os; } template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) { for (ll i = 0; i < vec.size(); ++i) { for (ll j = 0; j < vec[i].size(); ++j) { os << vec[i][j] << " "; } os << endl; } return os; } template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) { os<<endl; for (auto &&v:m) os << v<<endl; return os; } template<class T> ostream &operator<<(ostream &os, set<T> s) { fora(v, s) { os << v << " "; } return os; } template<class T> ostream &operator<<(ostream &os, mset<T> s) { fora(v, s) { os << v << " "; } return os; } template<class T> ostream &operator<<(ostream &os, deque<T> a) { fora(v, a)os << v << " "; return os; } ostream &operator<<(ostream &os, vector<vector<char>> &vec) { rep(h, sz(vec)) { rep(w, sz(vec[0])) { os << vec[h][w]; } os << endl; } return os; } //template<class T,class U>ostream &operator<<(ostream &os, vector<pair<T,U>>& a) {fora(v,a)os<<v<<endl;return os;} /*@formatter:off*/ template<typename W, typename H> void resize(W &vec, const H head) { vec.resize(head); } template<typename W, typename H, typename ... T> void resize(W &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);} //template<typename W, typename H> void resize(vector<W> &vec, const H head) { vec.resize(head); } //template<typename W, typename H, typename ... T> void resize(vector<W> &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);} template<typename T, typename F> bool all_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool all_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool any_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool any_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;} template<typename T, typename F> bool none_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool none_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool find_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll find_if2(vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);} template<typename T, typename F> bool rfind_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll rfind_if2(vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;} template<class T> bool contains(string &s, const T &v) { return s.find(v) != string::npos; } template<typename T> bool contains(vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); } template<typename T, typename F> bool contains_if2(vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); } template<typename T, typename F> ll count_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll count_if2(vector<T> &vec, F f) { ll ret = 0; fora(v, vec)ret += count_if2(v, f); return ret;} template<typename T, typename F> void for_each2(T &v, F f) { f(v); } template<typename T, typename F> void for_each2(vector<T> &vec, F f) { fora(v, vec)for_each2(v, f); } template<typename W> ll count_od(vector<W> &a) {return count_if2(a,[](ll v){return v&1 ;});} template<typename W> ll count_ev(vector<W> &a) {return count_if2(a,[](ll v){return !(v&1) ;});} //削除した後のvectorを返す template<typename T, typename F> vector<T> erase_if2(vector<T> &v, F f) {vector<T> nv;rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }}return nv;} template<typename T, typename F> vector<vector<T>> erase_if2(vector<vector<T>> &v, F f) {vector<vector<T>> res;rep(i, sz(v)) { res[i] = erase_if2(v[i], f); }return res;} template<typename T, typename F> vector<T> l_erase_if2(vector<T> &v, F f) {vector<T> nv;rep(i, sz(v)) { if (!f(v[i])) { nv.push_back(v[i]); }}return nv;} template<typename T, typename F> ll l_rfind_if(vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return i; } return -1;} template<typename T, typename F> bool l_contains_if(vector<T> &v, F f) { rer(i, sz(v) - 1) { if (f(v[i]))return true; } return false;} template<class A,class B, class C> auto t_all_of(A a,B b, C c){return std::all_of(a,b,c);} template<class A,class B, class C> auto t_any_of(A a,B b, C c){return std::any_of(a,b,c);} template<class A,class B, class C> auto t_none_of(A a,B b, C c){return std::none_of(a,b,c);} template<class A,class B, class C> auto t_find_if(A a,B b, C c){return std::find_if(a,b,c);} template<class A,class B, class C> auto t_count_if(A a,B b, C c){return std::count_if(a,b,c);} #define all_of_s__2(a,right) (t_all_of(all(a),lamr(right))) #define all_of_s__3(a,v,siki) (t_all_of(all(a),[&](auto v){return siki;})) #define all_of_s(...) over3(__VA_ARGS__,all_of_s__3,all_of_s__2)(__VA_ARGS__) //all_of(A, %2); //all_of(A, a, a%2); #define all_of__2(a,right) all_of2(a,lamr(right)) #define all_of__3(a,v,siki) all_of2(a,[&](auto v){return siki;}) #define all_of(...) over3(__VA_ARGS__,all_of__3,all_of__2)(__VA_ARGS__) #define all_of_f(a,f) all_of2(a,f) #define any_of_s__2(a,right) (t_any_of(all(a),lamr(right))) #define any_of_s__3(a,v,siki) (t_any_of(all(a),[&](auto v){return siki;})) #define any_of_s(...) over3(__VA_ARGS__,any_of_s__3,any_of_s__2)(__VA_ARGS__) #define any_of__2(a,right) any_of2(a,lamr(right)) #define any_of__3(a,v, siki) any_of2(a,[&](auto v){return siki;}) #define any_of(...) over3(__VA_ARGS__,any_of__3,any_of__2)(__VA_ARGS__) #define any_of_f(a,f) any_of2(a,f) #define none_of_s__2(a,right) (t_none_of(all(a),lamr(right))) #define none_of_s__3(a,v,siki) (t_none_of(all(a),[&](auto v){return siki;})) #define none_of_s(...) over3(__VA_ARGS__,none_of_s__3,none_of_s__2)(__VA_ARGS__) #define none_of__2(a,right) none_of2(a,lamr(right)) #define none_of__3(a,v, siki) none_of2(a,[&](auto v){return siki;}) #define none_of(...) over3(__VA_ARGS__,none_of__3,none_of__2)(__VA_ARGS__) #define none_of_f(a,f) none_of2(a,f) #define find_if_s__2(a,right) (t_find_if(all(a),lamr(right))-a.begin()) #define find_if_s__3(a,v,siki) (t_find_if(all(a),[&](auto v){return siki;})-a.begin()) #define find_if_s(...) over3(__VA_ARGS__,find_if_s__3,find_if_s__2)(__VA_ARGS__) #define find_if__2(a,right) find_if2(a,lamr(right)) #define find_if__3(a,v, siki) find_if2(a,[&](auto v){return siki;}) #define find_if(...) over3(__VA_ARGS__,find_if__3,find_if__2)(__VA_ARGS__) #define find_if_f(a,f) find_if2(a,f) #define rfind_if_s__2(a,right) l_rfind_if(a, lamr(right)) #define rfind_if_s__3(a,v,siki) l_rfind_if(a, [&](auto v){return siki;}) #define rfind_if_s(...) over3(__VA_ARGS__,rfind_if_s__3,rfind_if_s__2)(__VA_ARGS__) #define rfind_if__2(a,right) rfind_if2(a,lamr(right)) #define rfind_if__3(a,v, siki) rfind_if2(a,[&](auto v){return siki;}) #define rfind_if(...) over3(__VA_ARGS__,rfind_if__3,rfind_if__2)(__VA_ARGS__) #define rfind_if_f(a,f) rfind_if2(a,f) #define contains_if_s__2(a,right) l_contains_if(a, lamr(right)) #define contains_if_s__3(a,v,siki) l_contains_if(a, [&](auto v){return siki;}) #define contains_if_s(...) over3(__VA_ARGS__,contains_if_s__3,contains_if_s__2)(__VA_ARGS__) #define contains_if__2(a,right) contains_if2(a,lamr(right)) #define contains_if__3(a,v, siki) contains_if2(a,[&](auto v){return siki;}) #define contains_if(...) over3(__VA_ARGS__,contains_if__3,contains_if__2)(__VA_ARGS__) #define contains_if_f(a,f) contains_if2(a,f) #define count_if_s__2(a,right) (t_count_if(all(a),lamr(right))) #define count_if_s__3(a,v,siki) (t_count_if(all(a),[&](auto v){return siki;})) #define count_if_s(...) over3(__VA_ARGS__,count_if_s__3,count_if_s__2)(__VA_ARGS__) #define count_if__2(a,right) count_if2(a,lamr(right)) #define count_if__3(a,v, siki) count_if2(a,[&](auto v){return siki;}) #define count_if(...) over3(__VA_ARGS__,count_if__3,count_if__2)(__VA_ARGS__) #define count_if_f(a,f) count_if2(a,f) #define for_each_s__2(a,right) do{fora(v,a){v right;}}while(0) #define for_each_s__3(a,v, siki) do{fora(v,a){siki;}}while(0) #define for_each_s(...) over3(__VA_ARGS__,for_each_s__3,for_each_s__2)(__VA_ARGS__) #define for_each__2(a,right) for_each2(a,lamr(right)) #define for_each__3(a,v, siki) for_each2(a,[&](auto v){return siki;}) #define for_each(...) over3(__VA_ARGS__,for_each__3,for_each__2)(__VA_ARGS__) #define for_each_f(a, f) for_each2(a, f); #define erase_if_s__2(a,right) l_erase_if2(a,lamr(right)) #define erase_if_s__3(a,v, siki) l_erase_if2(a,[&](auto v){return siki;}) #define erase_if_s(...) over3(__VA_ARGS__,erase_if_s__3,erase_if_s__2)(__VA_ARGS__) #define erase_if__2(a,right) erase_if2(a,lamr(right)) #define erase_if__3(a,v, siki) erase_if2(a,[&](auto v){return siki;}) #define erase_if(...) over3(__VA_ARGS__,erase_if__3,erase_if__2)(__VA_ARGS__) #define erase_if_f(a,f) erase_if2(a,f) #define entry_if_s__2(a,right) l_entry_if2(a,lamr(right)) #define entry_if_s__3(a,v, siki) l_entry_if2(a,[&](auto v){return siki;}) #define entry_if_s(...) over3(__VA_ARGS__,entry_if_s__3,entry_if_s__2)(__VA_ARGS__) #define entry_if__2(a,right) entry_if2(a,lamr(right)) #define entry_if__3(a,v, siki) entry_if2(a,[&](auto v){return siki;}) #define entry_if(...) over3(__VA_ARGS__,entry_if__3,entry_if__2)(__VA_ARGS__) #define entry_if_f(a,f) entry_if2(a,f) template<class T, class U,class W> void replace(vector<W> &a, T key, U v) { rep(i,sz(a))if(a[i]==key)a[i]=v; } template<class T, class U,class W> void replace(vector<vector<W>> &A, T key, U v) { rep(i,sz(A))replace(A[i], key, v); } void replace(str &a, char key, str v) { if (v == "")a.erase(remove(all(a), key), a.end()); } void replace(str &a, char key, char v) { replace(all(a), key, v); } //keyと同じかどうか01で置き換える template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; } template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; } //template<class T> void replace(T &a) { replace(a, '#'); } void replace(str &a) { int dec = 0; if('a'<=a[0]&&a[0]<='z')dec = 'a'; if('A'<=a[0]&&a[0]<='Z')dec = 'A'; fora(v,a)v-=dec;} void replace(str &a, str key, str v) {stringstream t;ll kn = sz(key);std::string::size_type Pos(a.find(key));ll l = 0;while (Pos != std::string::npos) {t << a.substr(l, Pos - l);t << v;l = Pos + kn;Pos = a.find(key, Pos + kn);}t << a.substr(l, sz(a) - l);a = t.str();} template<class T> bool includes(vector<T> &a, vector<T> &b) {vi c = a;vi d = b;sort(all(c));sort(all(d));return includes(all(c), all(d));} template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(all(a), all(b)); } template<class T> bool next_permutation(vector<T> &a) { return next_permutation(all(a)); } void iota(vector<ll> &ve, ll s, ll n) {ve.resize(n);iota(all(ve), s);} vi iota(ll s, ll len) {vi ve(len);iota(all(ve), s);return ve;} template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]);return res;} template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;} template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;} template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;} enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd }; enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd}; template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) { typedef pair<A, B> U; if (type == fisi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });};template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; });};template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) { typedef F2<A, B, C, D> U; if (type == fisi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });};template<class U> void sort(vector<U> &a, tcomparator type) { if (type == 0) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });}template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });} void sort(string &a) { sort(all(a)); } void sort(int& a,int& b){ if(a>b)swap(a,b);} void sort(int& a,int& b, int& c){ sort(a,b); sort(a,c); sort(b,c);} void rsort(int& a,int& b){ if(a<b)swap(a,b);} void rsort(int& a,int& b, int& c){ rsort(a,b); rsort(a,c); rsort(b,c);} template<class T> void sort(vector<T> &a) { sort(all(a)); } //P l, P rで f(P) の形で渡す template<class U, class F> void sort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) < f(r); }); }; template<class T> void rsort(vector<T> &a) { sort(all(a), greater<T>()); }; template<class U, class F> void rsort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) > f(r); }); }; //F = T<T> //例えばreturn p.fi + p.se; template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;} template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} //sortindex 元のvectorはソートしない template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}/*indexの分で型が変わるためpcomparatorが必要*/template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;}template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;}template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;}template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;}template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;}template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;}template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); };template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;}template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); };template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;}template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;}template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; } }); return ind;}template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;}template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; } }); return ind;} template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); } template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); } template<class... T,class U> auto sorted(U head,T... a) { sort(head,a...); return head;} template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; }template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; }template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; } template<typename W, typename T>void fill(W &xx, const T vall) { xx = vall;}template<typename W, typename T>void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall);} template<typename W,typename T>void fill(vector<W> &xx,ll len,const T v) {rep(i, len)xx[i]=v;} template<typename W, typename T> void fill(vector<vector<W>> &xx, int sh, int th, int sw, int tw, T v) { rep(h, sh, th)rep(w, sw, tw)xx[h][w] = v; } template<class T,class U>void fill(vector<T> &a,vi& ind,U val) {fora(v,ind)a[v]=val;} template<class W,class T>void fill(mvec<W> &xx,const T v){ fora(x,xx)fill(x,v); } template<typename A, size_t N> A sum(A (&a)[N]) { A res = 0; rep(i, N)res += a[i]; return res;}template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) { A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;}template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;} //@汎用便利関数 入力 ll in() {ll ret;cin >> ret;return ret;} string sin() {string ret;cin >> ret;return ret;} template<class T> void in(T &head) { cin >> head; }template<class T, class... U> void in(T &head, U &... tail) {cin >> head;in(tail...);} #define din1(a) ll a;cin>>a #define din2(a, b) ll a,b;cin>>a>> b #define din3(a, b, c) ll a,b,c;cin>>a>>b>>c #define din4(a, b, c, d) ll a,b,c,d;cin>>a>>b>>c>>d #define din5(a, b, c, d, e) ll a,b,c,d,e;cin>>a>>b>>c>>d>>e #define din6(a, b, c, d, e, f) ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f #define din(...) over6(__VA_ARGS__,din6,din5,din4,din3,din2 ,din1)(__VA_ARGS__) #define dins1(a) str a;cin>>a #define dins2(a, b) str a,b;cin>>a>> b #define dins3(a, b, c) str a,b,c;cin>>a>>b>>c #define dins4(a, b, c, d) str a,b,c,d;cin>>a>>b>>c>>d #define dins5(a, b, c, d, e) str a,b,c,d,e;cin>>a>>b>>c>>d>>e #define dins6(a, b, c, d, e, f) str a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f #define dins(...) over6(__VA_ARGS__,dins6,dins5,dins4,dins3,dins2 ,dins1)(__VA_ARGS__) #define din1d(a) din1(a);a-- #define din2d(a, b) din2(a,b);a--,b-- #define din3d(a, b, c) din3(a,b,c);a--,b--,c-- #define din4d(a, b, c, d) din4(a,b,c,d);a--,b--,c--,d-- #define dind(...) over4(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__) template<class T> void out2(T &&head) { cout << head; } template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);} template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;} template<class T> void out(T &&head) { cout << head << endl;} void out() { cout << "" << endl;} #ifdef _DEBUG template<class T> void err2(T &&head) { cerr << head; } template<class T, class... U> void err2(T &&head, U &&... tail) { cerr << head << " "; err2(tail...);} template<class T, class... U> void err(T &&head, U &&... tail) { cerr << head << " "; err2(tail...); cerr << "" << endl;} template<class T> void err(T &&head) { cerr << head << endl;} void err() { cerr << "" << endl;} template<class T> string out_m2(vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), 12ll); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << a[i]; if (typeid(a[i]) == typeid(P)) { ss << endl; } else { ss << " "; } } return ss.str();} template<class T> string out_m2(vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) {H = min({H, sz(a), 12ll});W = min({W, sz(a[0]), 12ll});stringstream ss;ss << endl;if (key == -1)ss << " *|"; else ss << " " << key << "|";rep(w, W)ss << std::right << std::setw(4) << w;ss << "" << endl;rep(w, W * 4 + 3)ss << "_";ss << "" << endl;rep(h, H) {ss << std::right << std::setw(2) << h << "|";rep(w, min(sz(a[h]),12ll)) { if (abs(a[h][w]) == linf) ss << " e" << ""; else ss << std::right << std::setw(4) << a[h][w]; }ss << "" << endl;}return ss.str();} template<class T> string out_m2(vector<vector<vector<T> > > &a, ll H = inf, ll W = inf, ll U = inf) {stringstream ss; if (H == inf)H = 12; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << out_m2(a[i], W, U, i); } return ss.str();} template<class T, size_t N> string out_m2(T (&a)[N]) { vector<T> b; resize(b, N); rep(i, N) { b[i] = a[i]; } return out_m2(b);} template<class T, size_t N, size_t M> string out_m2(T (&a)[N][M]) { vector<vector<T>> b; resize(b, N, M); rep(i, N) { rep(j, M) { b[i][j] = a[i][j]; } } return out_m2(b);} template<class T, size_t N, size_t M, size_t O> string out_m2(T (&a)[N][M][O]) { vector<vector<vector<T>>> b; resize(b, N, M, O); rep(i, N) { rep(j, M) { rep(k, O) { b[i][j][k] = a[i][j][k]; } } } return out_m2(b);} string out_m2(int a) {stringstream ss;ss << a;return ss.str();} /*@formatter:on*/ template<class T> string out_m2(mvec<mvec<T> > &a, ll H = inf, ll W = inf, int key = inf) { H = min({H, sz(a), 6ll}); W = min({W, sz(a[0]), 6ll}); stringstream ss; ss << endl; // if (key == inf)ss << " *|"; else ss << " " << key << "|"; if (key == inf)ss << " *|"; else { ss << std::right << std::setw(2) << key; ss << "|"; } rep(w, -W, W)ss << std::right << std::setw(4) << w; ss << "" << endl; rep(w, W * 8 + 3)ss << "_"; ss << "" << endl; rep(h, -H, H) { ss << std::right << std::setw(2) << h << "|"; int NW = min(sz(a[h]), 6ll); rep(w, -NW, NW) { if (abs(a[h][w]) == linf) ss << " e" << ""; else ss << std::right << std::setw(4) << a[h][w]; } ss << "" << endl; } return ss.str(); }/*@formatter:on*/ template<class T> string out_m2(mvec<mvec<mvec<T> > > &a, ll H = inf, ll W = inf, ll U = inf) { stringstream ss; if (H == inf)H = 6; H = min(H, sz(a)); rep(i, -H, H) { ss << endl; ss << out_m2(a[i], W, U, i); } return ss.str(); } /*@formatter:off*/ template<class T> string out_m2(T &a) {stringstream ss;ss << a;return ss.str();} /*@formatter:on*/ template<class T> string out_m(vector<T> &a, ll W = inf) { stringstream ss; if (W == inf)W = min(sz(a), 12ll); if (sz(a) == 0)return ss.str(); rep(i, W) { ss << a[i] << " "; } ss << "" << endl; return ss.str(); } /*@formatter:off*/ template<class T> string out_m(vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) {H = min({H, sz(a), 12ll});W = min({W, sz(a[0]), 12ll});stringstream ss;ss << endl;if (key == -1)ss << " *|"; else ss << " " << key << "|";rep(w, W)ss << std::right << std::setw(4) << w;ss << "" << endl;rep(w, W * 4 + 3)ss << "_";ss << "" << endl;rep(h, H) {ss << std::right << std::setw(2) << h << "|";rep(w, min(sz(a[h]),12ll)) { if (abs(a[h][w]) == linf) ss << " e" << ""; else ss << std::right << std::setw(4) << a[h][w]; }ss << "" << endl;}ss << endl;return ss.str();} template<class T> string out_m(vector<vector<vector<T> > > &a, ll H = inf, ll W = inf, ll U = inf) {stringstream ss; if (H == inf)H = 5; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << out_m(a[i], W, U, i); } ss << endl; return ss.str();} string out_m(int a) {stringstream ss;ss << a << endl;return ss.str();} template<class T> string out_m(T &a) {stringstream ss;ss << a << endl;return ss.str();} template<class T> void outv(vector<T> &a, ll W=inf) {cout << out_m(a,W) << endl;} template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) { cout << out_m(a,H,W,key) << endl;} template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {cout << out_m(a,H,W,U)<< endl;} #else template<class T> void outv(vector<T> &a, ll W = inf) { rep(i, min(W, sz(a))) { cout << a[i] << " "; } cout << "" << endl; } template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf, int key = -1) { rep(i, min(H, sz(a))) { outv(a[i], W); }} template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf, ll U = linf) { ; } #define err(...); #endif template<class T> void outl(vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; } //テーブルをスペースなしで出力 template<class T> void outt(vector<vector<T>> &a) { rep(i, sz(a)) { rep(j, sz(a[i])) { cout << a[i][j]; } cout << endl; } } //int型をbit表記で出力 void outb(int a) { cout << bitset<20>(a) << endl; } template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i]; } template<class T> void na(set<T> &a, ll n) { rep(i, n)a.insert(in()); } #define dna(a, n) vi a(n); rep(dnai,n) cin >> a[dnai]; #define dnad(a, n) vi a(n); rep(dnai,n) cin >> a[dnai],a[dnai]--; template<class T> void nao(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1]; } template<class T> void naod(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1], a[i + 1]--; } template<class T> void nad(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i], a[i]--; } template<class T> void nad(set<T> &a, ll n) { rep(i, n)a.insert(in()-1); } template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i]; } template<class T, class U> void na2(set<T> &a, set<U> &b, ll n) { rep(i, n){ a.insert(in()); b.insert(in()); } } #define dna2(a, b, n) vi a(n),b(n);rep(dna2i, n)cin >> a[dna2i] >> b[dna2i]; template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) { a.resize(n + 1); b.resize(n + 1); a[0] = b[0] = 0; rep(i, n)cin >> a[i + 1] >> b[i + 1]; } #define dna2d(a, b, n) vi a(n),b(n);rep(dna2di, n){cin >> a[dna2di] >> b[dna2di];a[dna2di]--,b[dna2di]--;} template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--; } template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) { a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i]; } #define dna3(a, b, c, n) vi a(n),b(n),c(n); rep(dna3i, n)cin >> a[dna3i] >> b[dna3i] >> c[dna3i]; template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) { a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--; } #define dna3d(a, b, c, n) vi a(n),b(n),c(n); rep(dna3di, n){cin >> a[dna3di] >> b[dna3di] >> c[dna3di];a[dna3di]--,b[dna3di]--,c[dna3di]--;} template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) { a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i]; } #define dna4(a, b, c, d, n) vi a(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i]; #define dna4d(a, b, c, d, n) vi a(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i],--a[dna4i] ,-- b[dna4i],-- c[dna4i],--d[dna4i]; #define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi]; #define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--; #define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi]; //デバッグ #define sp << " " << #define deb1(x) debugName(x)<<" = "<<out_m2(x) #define deb_2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__) #define deb_3(x, ...) deb1(x) <<", "<< deb_2(__VA_ARGS__) #define deb_4(x, ...) deb1(x) <<", "<< deb_3(__VA_ARGS__) #define deb5(x, ...) deb1(x) <<", "<< deb_4(__VA_ARGS__) #define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__) #define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__) #define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__) #define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__) #define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__) #ifdef _DEBUG #define deb(...) cerr<< over10(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb_4,deb_3,deb_2,deb1)(__VA_ARGS__) <<endl #define base_keta 8 void print_n_base(int x,int base){ cerr<<bitset<base_keta>(x)<<endl;} template<class T>void print_n_base(vector<T> X,int base){ cerr<<endl; for(auto&& x:X){ print_n_base(x,base); } cerr<<endl;} //n進数 #define deb2(x) cerr<<debugName(x)<<" = ";print_n_base(x, 2); #define deb3(x) cerr<<debugName(x)<<" = ";print_n_base(x, 3); #define deb4(x) cerr<<debugName(x)<<" = ";print_n_base(x, 4); #else #define deb(...) ; #define deb2(...) ; #define deb3(...) ; #define deb4(...) ; #endif #define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n' //@formatter:off //よく使うクラス、構造体 //graphでredefineしているため、書き換えたら向こうも書き換える struct unionfind { vector<ll> par; vector<ll> siz; vector<ll> es; ll n, trees;//連結グループの数(親の種類) unionfind(ll n) : n(n), trees(n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }} ll operator()(ll x){return root(x);} bool unite(ll x, ll y) { x = root(x); y = root(y); es[x]++; if (x == y) return false; if (siz[x] > siz[y]) swap(x, y); trees--; par[x] = y; siz[y] += siz[x]; es[y] += es[x]; return true; } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } ll esize(ll x) { return es[root(x)]; } vi sizes(){ vi cou(n); vi ret; ret.reserve(n); rep(i, n){ cou[root (i)]++; } rep(i, n){ if(cou[i])ret.push_back(cou[i]); } return ret; } //つながりを無向グラフと見なし、xが閉路に含まれるか判定 bool close(ll x) { return esize(x) >= size(x); } vector<vi> sets() { vi ind(n, -1); ll i = 0; vvi(res, trees); rep(j, n) { ll r = root(j); if (ind[r] == -1)ind[r] = i++; res[ind[r]].push_back(j); } rep(i, trees) { ll r = root(res[i][0]); if (res[i][0] == r)continue; rep(j, 1, sz(res[i])) { if (res[i][j] == r) { swap(res[i][0], res[i][j]); break; } } } return res; } };//@formatter:off using u32 = unsigned; using u64 = unsigned long long; using u128 = __uint128_t; using bint =__int128; std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest;} __int128 to_bint(string &s) { __int128 ret = 0; for (ll i = 0; i < s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;} void operator>>(istream &iss, bint &v) { string S; iss>>S; v = 0; rep(i,sz(S)){ v*=10; v += S[i]-'0'; } } bint max(bint a, signed b){return max(a,(bint)b);} bint max(signed a, bint b){return max((bint)a, b);} bint max(bint a, ll b){return max(a,(bint)b);} bint max(ll a, bint b){return max((bint)a, b);} bint min(bint a, signed b){return min(a,(bint)b);} bint min(signed a, bint b){return min((bint)a, b);} bint min(bint a, ll b){return min(a,(bint)b);} bint min(ll a, bint b){return min((bint)a, b);} //エラー void ole() { #ifdef _DEBUG debugline("ole"); exit(0); #endif string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl; exit(0);} void re() { assert(0 == 1); exit(0);} void tle() { while (inf)cout << inf << endl; } //便利関数 //テスト用 #define rand xor128_ unsigned long xor128_(void){static unsigned long x=123456789,y=362436069,z=521288629,w=88675123;unsigned long t;t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );} char ranc() { return (char) ('a' + rand() % 26); } ll rand(ll min, ll max) { assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}} ll rand(ll max){return rand(0,max);} template<class T> T rand(vector<T>& A){return A[rand(sz(A)-1)];} //重複することがある template<class T> vector<T> ranv(vector<T>& A, int N){vector<T>ret(N);rep(i,N){ret[i]=rand(A);}return ret;} template<class T> vector<T> ranv_unique(vector<T>& A, int N){ vector<T> ret(N); umapi was; rep(j,N){ int i; while(1){ i = rand(sz(A)-1); if(was.find(i) == was.end())break; } ret[j] = A[i];was[i]=1; } return ret;} vi ranv(ll n, ll min, ll max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v;} str ransu(ll n) { str s; rep(i, n)s += (char) rand('A', 'Z'); return s;} str ransl(ll n) { str s; rep(i, n)s += (char) rand('a', 'z'); return s;} //単調増加 vi ranvinc(ll n, ll min, ll max) { vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;} //便利 汎用 void ranvlr(ll n, ll min, ll max, vi &l, vi &r) { l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }} template<class T>vector<pair<T,int>> run_length(vector<T> &a) {vector<pair<T,int>> ret;ret.eb(a[0], 1);rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }}return ret;} vector<pair<char, ll>> run_length(string &a) { vector<pair<char, ll>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} /*@formatter:on*/ template<class T, class F> T mgr(T ok, T ng, F f) { bool han = true; if (ok < ng) while (ng - ok > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } else while (ok - ng > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } return ok; } template<class T, class F> T mgr(signed ok_, T ng, F f) { T ok = ok_; bool han = true; if (ok < ng) while (ng - ok > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } else while (ok - ng > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } return ok; } template<class T, class F> T mgr(T ok, signed ng_, F f) { T ng = ng_; bool han = true; if (ok < ng) while (ng - ok > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } else while (ok - ng > 1) { T mid = (ok + ng) >> 1; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid, han); } return ok; } /*@formatter:off*/ template<class F> dou mgrd(dou ok, dou ng, F f,int kai=100) { bool han = true; if (ok < ng) rep(i,kai) { dou mid = (ok + ng) /2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid,han); } else rep(i,kai) { dou mid = (ok + ng) /2; if (f(mid))ok = mid, han = true; else ng = mid, han = false; deb(mid,han); } return ok; } //strを整数として比較 string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a;} //strを整数として比較 string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a;} //エラー-1 template<typename W, typename T> ll find(vector<W> &a, int l, const T key) {rep(i, l, sz(a))if (a[i] == key)return i;return -1;} template<typename W, typename T> ll find(vector<W> &a, const T key) { rep(i, sz(a))if (a[i] == key)return i; return -1;} template<typename W, typename T> P find(vector<vector<W >> &a, const T key) { rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j); return mp(-1, -1);} //getid(find())を返す 1次元にする template<typename W, typename T> int findi(vector<vector<W >> &a, const T key) { rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return i*sz(a[0])+j; return -1;} template<typename W, typename U> T find(vector<vector<vector<W >>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return mt(i, j, k); return mt(-1, -1, -1);} //stringも書く int find(string& s, const string key){ int klen = sz(key); rep(i,sz(s)-klen+1){ if(s[i]!=key[0])continue; if(s.substr(i,klen) == key){ return i; } } return -1;} int find(string& s, int l, const string key){ int klen = sz(key); rep(i, l, sz(s)-klen+1){ if(s[i]!=key[0])continue; if(s.substr(i,klen) == key){ return i; } } return -1;} int find(string& s, const char key){ rep(i,sz(s)){ if(s[i]==key)return i; } return -1;} int find(string& s, int l, const char key){ rep(i, l, sz(s)){ if(s[i]==key)return i; } return -1;} template<typename W, typename T> ll count2(W &a, const T k) { return a == k; } template<typename W, typename T> ll count2(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;} template<typename W, typename T> ll count(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;} vi count(vi &a) { int ma = 0; fora(v, a) { if (ma < v)ma = v; } vi res(ma + 1); fora(v, a) { res[v]++; } return res;} ll count(str &a, str k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;} //'a' = 'A' = 0 として集計 既に-'a'されていても動く vi count(str &a, int l, int r) { vi cou(26); char c = 'a'; if ('A' <= a[l] && a[l] <= 'Z')c = 'A'; if ('a' <= a[l] && a[l] <= 'z') c = 'a'; else c = 0; rep(i, l, r)++cou[a[i] - c]; return cou;} vi count(str &a, int r = inf){return count(a, 0, min(r, sz(a)));} #define couif count_if //algorythm ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;} template<class T> void rev(vector<T> &a) { reverse(all(a)); } template<class U> void rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; a = b;} void rev(string &a) { reverse(all(a)); } constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll}; //0は0桁 ll keta(ll v) { if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) { if (v < p10[0])return 0; else return 1; } else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else return 15; } else { if (v < p10[17]) { if (v < p10[16]) return 16; else return 17; } else { if (v < p10[18])return 18; else return 19; } } } }} ll getr(ll a, ll keta) { return (a / (ll) pow(10, keta)) % 10; } //上から何桁目か ll getl(ll a, ll ket) {int sketa = keta(a);return getr(a,sketa-1-ket);} ll dsum(ll v,ll sin=10) { ll ret = 0; for (; v; v /= sin)ret += v % sin; return ret;} ll mask10(ll v) { return p10[v] - 1; } //変換系 //[v] := iとなるようなvectorを返す //存在しない物は-1 template<class T> auto keys(T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;} template<class T> auto values(T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;} template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;} template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;} template<class T> constexpr T min(T a, signed b) { return a < b ? a : b; } template<class T> constexpr T max(T a, signed b) { return a < b ? b : a; } template<class T> constexpr T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; } template<class T> constexpr T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; } template<class T> T min(vector<T>& a) { return *min_element(all(a)); } template<class T> T mini(vector<T>& a) { return min_element(all(a)) - a.begin(); } template<class T> T min(vector<T>& a, ll n) { return *min_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T min(vector<T>& a, ll s, ll n) { return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<class T> T max(vector<T>& a) { return *max_element(all(a)); } template<class T,class U> T max(vector<T>& a,vector<U>& b) { return max(*max_element(all(a)),*max_element(all(b))); } template<class T> T maxi(vector<T>& a) { return max_element(all(a)) - a.begin(); } template<class T> T max(vector<T>& a, ll n) { return *max_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T max(vector<T>& a, ll s, ll n) { return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<typename A, size_t N> A max(A (&a)[N]) { A res = a[0]; rep(i, N)res = max(res, a[i]); return res;}template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;}template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<class T> T sum(vector<T> &v, ll s, ll t) { T ret = 0; rep(i, s, min(sz(v), t))ret += v[i]; return ret;} template<class T> T sum(vector<T> &v, ll t = inf) { return sum(v, 0, t); } template<class T> T sum(vector<vector<T> > &v, int s, int t) {T ret = 0;rep(i, s, min(sz(v), t))ret += sum(v[i]);return ret;} template<class T> T sum(vector<vector<T> > &v, int t = inf) { return sum(v, 0, t); } template<class T> T sum(vector<vector<vector<T>> > &v, int s, int t) {T ret = 0;rep(i, s, min(sz(v), t))ret += sum(v[i]);return ret;} template<class T> T sum(vector<vector<vector<T>> > &v, int t = inf) { return sum(v, 0, t); } template<class T> T sum(vector<vector<vector<vector<T>>> > &v, int s, int t) {T ret = 0;rep(i, s, min(sz(v), t))ret += sum(v[i]);return ret;} template<class T> T sum(vector<vector<vector<vector<T>>> > &v, int t = inf) { return sum(v, 0, t); } template<class T> T sum(vector<vector<vector<vector<vector<T>>>> > &v, int s, int t) {T ret = 0;rep(i, s, min(sz(v), t))ret += sum(v[i]);return ret;} template<class T> T sum(vector<vector<vector<vector<vector<T>>>> > &v, int t = inf) { return sum(v, 0, t); } template<class T> auto sum(priority_queue<T, vector<T>, greater<T> > &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;} template<class T> auto sum(priority_queue<T> &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;} template<class T> T mul(vector<T> &v, ll t = inf) { T ret = v[0]; rep(i, 1, min(t, sz(v)))ret *= v[i]; return ret;} //template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;} vi v_i(vi &a) { int n = max(a) + 1; vi ret(n, -1); rep(i, sz(a)) { ret[a[i]] = i; } return ret;} void clear(PQ &q) { q = PQ(); } void clear(priority_queue<int>&q) { q = priority_queue<int>();} template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); } template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;} template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;} //imoは0-indexed //ruiは1-indexed template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;} //kと同じものの数 template<class T, class U> vi imo(vector<T> &a, U k) {vector<T> ret = a;rep(i, sz(ret))ret[i] = a[i] == k;rep(i, sz(ret) - 1)ret[i + 1] += ret[i];return ret;} template<class T> vector<T> imox(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;} //漸化的に最小を持つ template<class T> vector<T> imi(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;} template<class T> vector<T> ima(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chma(ret[i + 1], ret[i]); return ret;} template<class T> vector<T> rimi(vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chmi(ret[i - 1], ret[i]); return ret;} template<class T> vector<T> rima(vector<T> &v) { vector<T> ret = v; rer(i, sz(ret) - 1, 1)chma(ret[i - 1], ret[i]); return ret;} template<class T> struct ruiC { vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} /*先頭0*/ ruiC() : rui(1, 0) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } return rui[r] - rui[l]; } T operator()(int r) { return operator()(0, r); } /*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/ /*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/ // T operator[](ll i) { return rui[i + 1] - rui[i]; } T operator[](ll i) { return rui[i]; } /*0から順に追加される必要がある*/ void operator+=(T v) { rui.push_back(rui.back() + v); } void add(int i, T v) {if (sz(rui) - 1 != i)ole();operator+=(v);} T back() { return rui.back(); } ll size() { return rui.size(); } auto begin(){return rui.begin();} auto end(){return rui.end();} }; template<class T> struct ruimax {template<typename Monoid>struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MIN(T), -1); Monoid f(Monoid a, Monoid b) { return max(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };private:vector<T> ve;SegmentTree<pair<T, int>> seg;vector<T> rv;vector<T> ri;bool build = false; public: int n; ruimax(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; int ma = MIN(T); rv.resize(n + 1); ri.resize(n + 1); rv[0] = -linf; ri[0] = -1; rep(i, n) { if (chma(ma, a[i])) { index = i; } rv[i + 1] = ma; ri[i + 1] = index; } } T operator()(int l, int r) { if (!(l <= r && 0 <= l && r <= n)) { deb(l, r, n); assert(0); } if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } } T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) { return operator()(0, r); } T getv(int l, int r) { return operator()(l, r); } T geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } T geti(int r = inf) { return geti(0, min(r,n)); }; T getv(int r = inf) { return getv(0, min(r,n)); }; auto begin(){return rv.begin();} auto end(){return rv.end();} }; template<class T> struct ruimin {template<typename Monoid> struct SegmentTree { /*pairで処理*/ int sz; vector<Monoid> seg; const Monoid M1 = mp(MAX(T), -1); Monoid f(Monoid a, Monoid b) { return min(a, b); } void build(vector<T> &a) { int n = sz(a); sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); rep(i, n) { seg[i + sz] = mp(a[i], i); } for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[k << 1], seg[(k << 1) | 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } };private:vector<T> ve;SegmentTree<pair<T, int>> seg;vector<T> rv;vector<T> ri;bool build = false;int n; public: ruimin(vector<T> &a) : ve(a), n(sz(a)) { int index = -1; int mi = MAX(T); rv.resize(n + 1); ri.resize(n + 1); rv[0] = linf; ri[0] = -1; rep(i, n) { if (chmi(mi, a[i])) { index = i; } rv[i + 1] = mi; ri[i + 1] = index; } } T operator()(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return rv[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).first; } } T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) {return operator()(0, r);} T getv(int l, int r) { return operator()(l, r); } T geti(int l, int r) { assert(l <= r && 0 <= l && r <= n); if (l == 0) { return ri[r]; } else { if (!build)seg.build(ve), build = true; return seg.query(l, r).second; } } T geti(int r = inf) { return geti(0, min(r,n)); }; T getv(int r = inf) { return getv(0, min(r,n)); }; auto begin(){return rv.begin();} auto end(){return rv.end();} }; template<class T>ostream &operator<<(ostream &os, ruiC<T> a) {fora(v,a.rui)os<<v<<" ";return os;} template<class T> vector<T> ruiv(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;} template<class T> ruiC<T> ruic() {return ruiC<T>();} template<class T> ruiC<T> ruic(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);} vvi() ruib(vi &a) { vvi(res, 61, sz(a) + 1); rep(k, 61) { rep(i, sz(a)) { res[k][i + 1] = res[k][i] + ((a[i] >> k) & 1); } } return res;} vector<ruiC<int>> ruibc(vi &a) { vector<ruiC<int>> ret(61); vvi(res, 61, sz(a)); rep(k, 61) { rep(i, sz(a)) { res[k][i] = (a[i] >> k) & 1; } ret[k] = ruic(res[k]); } return ret;} vector<ll> ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector<ll> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;} ruiC<ll> ruic(string &a) { vector<ll> ret = ruiv(a); return ruiC<ll>(ret);} //kと同じものの数 template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;} template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);} template<class T> struct ruiC2 { int H; vector<ruiC<T>> rui; ruiC2(vector<vector<T>> &ru) : rui(sz(ru)),H(sz(ru)) { for (int h = 0; h < H; h++){ rui[h] = ruic(ru[h]); } } //WについてHを返す vector<T> operator()(ll l, ll r) { if (l > r) { cerr << "ruic "; deb(l, r); assert(0); } vector<T> res(H); for (int h = 0; h < H; h++)res[h]=rui[h](l, r); return res; } //HについてWを返す ruiC<T> operator[](ll h){ assert(h<H);return rui[h]; } // vector<T> operator()(int r) { return operator()(0, r); } /*ruiv[]をruic[]に変えた際意味が変わるのがまずいため()と統一*/ /*単体iを返す 累積でないことに注意(seg木との統一でこうしている)*/ // T operator[](ll i) { return rui[i + 1] - rui[i]; } /*0から順に追加される必要がある*/ // T back() { return rui.back(); } // ll size() { return rui.size(); } // auto begin(){return rui.begin();} // auto end(){return rui.end();} }; //a~zを0~25として // rui(l,r)でvector(26文字について, l~rのcの個数) // rui[h] ruic()を返す ruiC2<ll> ruicou(str &a) { str s = a; replace(s); vector<ruiC<ll>> res(26); vvi(cou, 26, sz(s)); rep(i, sz(s)) { cou[s[i]][i] = 1; } return ruiC2<ll>(cou);} ruiC2<ll> ruicou(vi &a) { int H = max(a) + 1; vector<ruiC<ll>> res(H); vvi(cou, H, sz(a)); rep(i, sz(a)) { cou[a[i]][i] = 1; } return ruiC2<ll>(cou);} /*@formatter:off*/ //h query template<class T> vector<T> imoh(vector<vector<T>> &v, int w) {vector<T> ret(sz(v));rep(h,sz(ret)){ret[h] = v[h][w];}rep(i, sz(ret) - 1){ret[i + 1] += ret[i];}return ret;} template<class T> vector<T> ruih(vector<vector<T>> &v, int w) {vector<T> ret(sz(v) + 1);rep(h, sz(v)) { ret[h + 1] = v[h][w]; }rep(i, sz(v)) { ret[i + 1] += ret[i]; }return ret;} template<class T> ruiC<T> ruihc(vector<vector<T>> &a, int w) {vector<T> ret = ruih(a, w);return ruiC<T>(ret);} //xor template<class T> struct ruixC { vector<T> rui; ruixC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); }}; template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;} template<class T> ruixC<ll> ruixc(vector<T> &a) {vi ret = ruix(a);return ruixC<ll>(ret);} template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;} //漸化的に最小を1indexで持つ template<class T> vector<T> ruimi(vector<T> &a) { ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;} //template<class T> T *rrui(vector<T> &a) { //右から左にかけての半開区間 (-1 n-1] template<class T> struct rruiC { vector<T> rui; int n; rruiC(vector<T> &a) : n(sz(a)) {rui.resize(n + 1);rer(i, n - 1) {rui[i] = rui[i + 1] + a[i];}} /*[r l)*/ T operator()(int r, int l) {r++;l++;assert(l <= r && l >= 0 && r <= n);return rui[l] - rui[r];} T operator()(int l) {return operator()(n - 1, l);} T operator[](int i) {return operator()(i);} }; template<class T> ostream &operator<<(ostream &os, rruiC<T> a) {fora(v, a.rui)os << v << " ";return os;} #define rrui rruic template<class T> rruiC<T> rruic(vector<T> &a) { return rruiC<T>(a); } //掛け算 template<class T> struct ruimulC { vector<T> rv; int n; ruimulC(vector<T> &a) : rv(a), n(sz(a)) {rv.resize(n + 1);rv[0] = 1;rep(i, n) { rv[i + 1] = a[i] * rv[i]; }} ruimulC() : n(0) {rv.resize(n + 1);rv[0] = 1;} void operator+=(T v) {rv.push_back(rv.back()*v);n++;} T operator()(int l, int r) {assert(l <= r && 0 <= l && r <= n);return rv[r] / rv[l];} T operator()(int r = inf) { return operator()(0, min(r, n)); } T operator[](int r) { return operator()(0, r); } auto begin() { return rv.begin(); } auto end() { return rv.end(); } }; template<class T> ruimulC<T> ruimul(vector<T> &a) { return ruimulC<T>(a); } template<class T> ruimulC<T> ruimul() {vector<T> a; return ruimulC<T>(a); } /*@formatter:off*/ template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;} template<class T, class U> void inc(pair<T,U> &a, U v = 1) { a.first += v,a.second+=v; } template<class T, class U> void inc(T &a, U v = 1) { a += v; } template<class T, class U = int> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); } template<class T, class U> void dec(T &a, U v = 1) { a -= v; } template<class T, class U = int> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class T,class U, class W> void dec(vector<T> &a,vector<U> &b, W v = 1) { for (auto &u :a)dec(u, v);for (auto &u :b)dec(u, v); } template<class T,class U,class W> void dec(vector<T> &a,vector<U> &b,vector<W>&c ) { for (auto &u :a)dec(u, 1);for (auto &u :b)dec(u, 1);for (auto &u :c)dec(u, 1); } bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; } bool ins(ll l, ll v, ll r) { return l <= v && v < r; } template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return ins(0, i, sz(a)) && ins(0, j, sz(a)); } #define inside ins ll u(ll a) { return a < 0 ? 0 : a; } template<class T> vector<T> u(vector<T> &a) { vector<T> ret = a; fora(v, ret)v = u(v); return ret;} //添え字を返す template<class F> ll goldd_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX(ll); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return resIndex;} template<class F> ll goldt_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN(ll); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return resIndex;} /*loopは200にすればおそらく大丈夫 余裕なら300に*/ template<class F> dou goldd_d(dou left, dou right, F calc, ll loop = 200) { dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} template<class F> dou goldt_d(dou left, dou right, F calc, ll loop = 200) { double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} //l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索 template<class F> ll goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX(ll); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> ll goldt_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN(ll); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} template<class F> dou goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX(dou); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> dou goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN(dou); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} template<class T> T min(vector<vector<T >> &a) { T res = MAX(T); rep(i, a.size())chmi(res, *min_element(all(a[i]))); return res;} template<class T> T max(vector<vector<T >> &a) { T res = MIN(T); rep(i, a.size())chma(res, *max_element(all(a[i]))); return res;} template<class T> T min(vector<vector<vector<T>>> &a) { T res = MAX(T); rep(i, a.size())chmi(res, min(a[i])); return res;} template<class T> T max(vector<vector<vector<T>>> &a) { T res = MIN(T); rep(i, a.size())chma(res, max(a[i])); return res;} template<class T> T min(vector<vector<vector<vector<T>>>> &a) { T res = MAX(T); rep(i, a.size())chmi(res, min(a[i])); return res;} template<class T> T max(vector<vector<vector<vector<T>>>> &a) { T res = MIN(T); rep(i, a.size())chma(res, max(a[i])); return res;} template<class T> T min(vector<vector<vector<vector<vector<T>>>>> &a) { T res = MAX(T); rep(i, a.size())chmi(res, min(a[i])); return res;} template<class T> T max(vector<vector<vector<vector<vector<T>>>>> &a) { T res = MIN(T); rep(i, a.size())chma(res, max(a[i])); return res;} template<class T> T min(vector<vector<vector<vector<vector<vector<T>>>>>> &a) { T res = MAX(T); rep(i, a.size())chmi(res, min(a[i])); return res;} template<class T> T max(vector<vector<vector<vector<vector<vector<T>>>>>> &a) { T res = MIN(T); rep(i, a.size())chma(res, max(a[i])); return res;} //pow周りの仕様 //powiを使うと整数型 //powbを使うとbint型 //powを使うと powlに変換され long doubleが返る #ifdef _DEBUG auto pow(ll a,ll k){ static bool was = 1; if(was){message +="if integer use *powi* it's very fast\n";} was=0; return powl(a,k);} //上のメッセージを出すための関数 auto pow(signed a,ll k){ return pow((ll)a,k);} auto pow(signed a,signed k){ return pow((ll)a,(ll)k);} #else #define pow powl #endif //整数型のpow int powi(int a, int k) { if (a == 2)return 1ll << k; int res = 1; int x = a; while (k) { if(k & 1)res *= x; x *= x; k >>= 1; } return res;} //define pow powlより上に動かすとバグる bint pow(bint a, ll k) { bint res = 1; bint x = a; while (k) { if(k & 1)res *= x; x *= x; k >>= 1; } return res;} bint pow(bint a, signed k) {return pow(a,(ll)k);} bint powb(int a, int b){return pow((bint)a,b);} constexpr bool bget(ll m, ll keta) { #ifdef _DEBUG assert(keta<=62);//オーバーフロー 1^62までしか扱えない #endif return (m >> keta) & 1; } //bget(n)次元 // NならN-1まで vector<vi> bget2(vi& a,int keta_size){ vvi(res,keta_size,sz(a)); rep(k,keta_size){ rep(i, sz(a)){ res[k][i]=bget(a[i],k); } } return res;} vi bget1(vi& a,int keta){ vi res(sz(a)); rep(i, sz(a)){ res[i]=bget(a[i],keta); } return res;} ll bget(ll m, ll keta, ll sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu;} constexpr ll bit(ll n) { #ifdef _DEBUG assert(n<=62);//オーバーフロー 1^62までしか扱えない #endif return (1LL << (n)); } ll bit(ll n, ll sinsuu) { return (ll) pow(sinsuu, n); } ll mask(ll n) { return (1ll << n) - 1; } //aをbitに置きなおす //{0, 2} -> 101 ll bit(vi&a){ int m=0; for(auto&& v:a) m|=bit(v); return m;} //{1, 1, 0} -> 011 //bitsetに置き換える感覚 i が立っていたら i bit目を立てる ll bitb(vi&a){ int m=0; rep(i,sz(a)) if(a[i])m|=bit(i); return m;} #define bcou __builtin_popcountll //最下位ビット ll lbit(ll n) { return n & -n; } ll lbiti(ll n) { return log2(n & -n); } //最上位ビット ll hbit(ll n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);} ll hbiti(ll n){return log2(hbit(n));} ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;} //初期化は0を渡す ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;} //n桁以下でビットがr個立っているもののvectorを返す vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;} //masの立ってるindexを見る #define forbit(i, mas) for (int forbitj = lbit(mas), forbitm = mas, i = log2(forbitj); forbitm; forbitm = forbitj ? forbitm ^ forbitj : 0, forbitj = lbit(forbitm), i = log2(forbitj)) char itoal(ll i) { return 'a' + i; } char itoaL(ll i) { return 'A' + i; } ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';} ll ctoi(char c) { return c - '0'; } char itoc(ll i) { return i + '0'; } ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;} vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } rev(res); return res;} vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;} //基準を満たさないものは0になる vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;} vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;} #define unique(v) v.erase( unique(v.begin(), v.end()), v.end() ); //[i] := vを返す //aは0~n-1で置き換えられる vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, umap<ll, ll> &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(all(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a)b.push_back(v); fora(v, r)b.push_back(v); sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a)b.push_back(v); fora(v, r)b.push_back(v); fora(v, s)b.push_back(v); sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(all(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vector<vi> &a) { vi b; fora(vv, a)fora(v, vv)b.push_back(v); sort(b); unique(b); fora(vv, a)fora(v, vv)v = lower_bound(all(b), v) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a)fora(vv, vvv)fora(v, vv)b.push_back(v); sort(b); unique(b); fora(vvv, a)fora(vv, vvv)fora(v, vv)v = lower_bound(all(b), v) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); }} //要素が見つからなかったときに困る #define binarySearch(a, v) (binary_search(all(a),v)) #define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin()) #define upperIndex(a, v) (upper_bound(all(a),v)-a.begin()) #define rlowerIndex(a, v) (upper_bound(all(a),v)-a.begin()-1) #define rupperIndex(a, v) (lower_bound(all(a),v)-a.begin()-1) template<class T, class U, class W> T lowerBound(vector<T> &a, U v, W banpei) {auto it = lower_bound(a.begin(), a.end(), v);if (it == a.end())return banpei; else return *it;}template<class T, class U, class W> T lowerBound(ruiC<T> &a, U v, W banpei) {return lowerBound(a.rui, v, banpei);} template<class T, class U, class W> T upperBound(vector<T>& a, U v, W banpei){ auto it = upper_bound(a.begin(),a.end(),v); if(it==a.end())return banpei; else return *it;}template<class T, class U, class W> T upperBound(ruiC<T> &a, U v, W banpei) {return upperBound(a.rui, v, banpei);} template<class T, class U, class W> T rlowerBound(vector<T> &a, U v, W banpei) { auto it = upper_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else{ return *(--it); }}template<class T, class U, class W> T rlowerBound(ruiC<T> &a, U v, W banpei) {return rlowerBound(a.rui, v, banpei);} template<class T, class U, class W> T rupperBound(vector<T> &a, U v, W banpei) { auto it = lower_bound(a.begin(), a.end(), v); if (it == a.begin())return banpei; else{ return *(--it); }}template<class T, class U, class W> T rupperBound(ruiC<T> &a, U v, W banpei) {return rupperBound(a.rui, v, banpei);} #define next2(a) next(next(a)) #define prev2(a) prev(prev(a)) //狭義の単調増加列 長さを返す template<class T> int lis(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX(T)); rep(i, n) { int id = lowerIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX(T));} template<class T> int lis_eq(vector<T> &a) { int n = sz(a); vi tail(n + 1, MAX(T)); rep(i, n) { int id = upperIndex(tail, a[i]);/**/ tail[id] = a[i]; } return lowerIndex(tail, MAX(T));} //iteratorを返す //valueが1以上の物を返す 0は見つけ次第削除 //vを減らす場合 (*it).se--でいい template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} //存在しなければエラー template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class... T> void fin(T... s) {out(s...); exit(0); } //便利 数学 math //sub ⊂ top bool subset(int sub, int top) {return (sub & top) == sub;} //-180 ~ 180 degree double atand(double h, double w) {return atan2(h, w) / PI * 180;} //% -mの場合、最小の正の数を返す ll mod(ll a, ll m) {if (m < 0) m *= -1;return (a % m + m) % m;} ll pow(ll a) { return a * a; }; ll fact(ll v) { return v <= 1 ? 1 : v * fact(v - 1); } dou factd(int v){static vd fact(2,1); if(sz(fact)<=v){ rep(i,sz(fact),v+1){ fact.push_back(fact.back()*i); } } return fact[v];} ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];} double comd2(ll n, ll r) { static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];} double comd(int n, int r) { if (r < 0 || r > n) return 0; if (n < 2020)return comd2(n, r); static vd fact(2, 1); if (sz(fact) <= n) { rep(i, sz(fact), n + 1) { fact.push_back(fact.back() * i); }} return fact[n] / fact[n - r] / fact[r];} ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);} ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;} ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;} ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }} ll sig0(int t) { return t <= 0 ? 0 : ((1 + t) * t) >> 1; } bint sig0(bint t) {return t <= 0 ? 0 : ((1 + t) * t) >> 1; } //ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; } ll sig(ll s, ll t) {if (s > t)swap(s, t);return sig0(t - s) + s * (t - s + 1);} #define tousa_i tosa_i #define lower_tousa_i lower_tosa_i #define upper_tousa upper_tosa #define upper_tousa_i upper_tosa_i ll tosa_i(ll st, ll ad, ll v) { assert(((v - st) % ad) == 0); return (v - st) / ad;} ll tosa_s(ll st, ll ad, ll len) { return st * len + sig0(len - 1) * ad;} // ax + r (x は非負整数) で表せる整数のうち、v 以上となる最小の整数 ll lower_tosa(ll st, ll ad, ll v) { if (st >= v) return st; return (v - st + ad - 1) / ad * ad + st;} //第何項か ll lower_tosa_i(ll st, ll ad, ll v) { if (st >= v) return 0; return (v - st + ad - 1) / ad;} ll upper_tosa(ll st, ll ad, ll v) { return lower_tosa(st, ad, v + 1); } ll upper_tosa_i(ll st, ll ad, ll v) { return lower_tosa_i(st, ad, v + 1); } //v * v >= aとなる最小のvを返す ll sqrt(ll a) { if (a < 0) { debugline("sqrt"); deb(a); ole(); } ll res = (ll) std::sqrt(a); while (res * res < a)++res; return res;} double log(double e, double x) { return log(x) / log(e); } /*@formatter:off*/ //機能拡張 #define dtie(a, b) int a, b; tie(a, b) template<class T, class U> string to_string(T a, U b) { string res = ""; res += a; res += b; return res;} template<class T, class U, class V> string to_string(T a, U b, V c) { string res = ""; res += a; res += b; res += c; return res;} template<class T, class U, class V, class W> string to_string(T a, U b, V c, W d) { string res = ""; res += a; res += b; res += c; res += d; return res;} template<class T, class U, class V, class W, class X> string to_string(T a, U b, V c, W d, X e) { string res = ""; res += a; res += b; res += c; res += d; res += e; return res;} constexpr int bsetlen = k5 * 2; //constexpr int bsetlen = 5050; #define bset bitset<bsetlen> bool operator<(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return false;} bool operator>(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return false;} bool operator<=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] < b[i])return true;if (a[i] > b[i])return false;}return true;} bool operator>=(bitset<bsetlen> &a, bitset<bsetlen> &b) {rer(i, bsetlen - 1) {if (a[i] > b[i])return true;if (a[i] < b[i])return false;}return true;} string operator~(string &a) {string res = a;for (auto &&c:res) {if (c == '0')c = '1';else if (c == '1')c = '0';else {cerr << "cant ~" << a << "must bit" << endl;exit(0);}}return res;} ostream &operator<<(ostream &os, bset& a) { bitset<10> b; vi list; rep(i,bsetlen){ if(a[i])list.push_back(i),b[i]=1; } os<<b<<", "<<list; return os;} int hbiti(bset&a){rer(i,bsetlen){if(a[i])return i;}return -1;} #define hk(a, b, c) (a <= b && b < c) //O(N/64) bset nap(bset &a, int v) {bset r = a | a << v;return r;} bset nap(bset &a, bset &v) {bset r = a;rep(i, bsetlen) {if (v[i])r |= a << i;}return r;} template<class T> void seth(vector<vector<T>> &S, int w, vector<T> &v) {assert(sz(S) == sz(v));assert(w < sz(S[0]));rep(h, sz(S)) { S[h][w] = v[h]; }} template<class T, class U> void operator+=(pair<T,U> &a, pair<T,U> & b) {a.fi+=b.fi;a.se+=b.se;} template<class T, class U> pair<T,U> operator+(pair<T,U> &a, pair<T,U> & b) {return pair<T,U>(a.fi+b.fi,a.se+b.se);} template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs += to_string(rv);}template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { lhs += to_string(rv);} template<typename CharT, typename Traits, typename Alloc> void operator*=(basic_string<CharT, Traits, Alloc> &s, int num) {auto bek = s;s = "";for (; num; num >>= 1) {if (num & 1) {s += bek;}bek += bek;}} template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v)a.push(d); return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v)a.insert(d); return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v); }template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v); }template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(vector<T> &a, U v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> vector<T> operator+(U v, vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(vector<T> a, vector<T> b) { vector<T> ret; ret = a; fora(v, b)ret += v; return ret;}template<class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) { rep(i, sz(b)) {/*こうしないとa+=aで両辺が増え続けてバグる*/ a.push_back(b[i]); } return a;}template<class T, class U> map<T, U> &operator+=(map<T, U> &a, map<T, U> &b) { fora(bv, b) { a[bv.first] += bv.second; } return a;} template<class T> void operator+=(mset<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); } template<class T> void operator+=(set<T> &a, vector<T>& v) { for(auto&& u : v)a.insert(u); } template<class T> void operator+=(vector<T> &a, set<T>& v) { for(auto&& u : v)a.emplace_back(u); } template<class T> void operator+=(vector<T> &a, mset<T>& v) { for(auto&& u : v)a.emplace_back(u); } template<class T> vector<T> &operator-=(vector<T> &a, vector <T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;} template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;} template<class T, class U> void operator*=(vector<T> &a, U b) { vector<T> ta = a; rep(b-1){ a+=ta; }} template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); } template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); } template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); } template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); } template<typename T> void insert(set<T> &v, vector<T> list) { for (auto &&va :list)v.insert(va); } template<class T> T poll(set<T>& S){T ret = *S.begin();S.erase(S.begin());return ret;} template<class T> T poll(mset<T>& S){T ret = *S.begin();S.erase(S.begin());return ret;} template<class T> T poll_back(set<T>& S){T ret = *S.rbegin();S.erase(S.rbegin());return ret;} template<class T> T poll_back(mset<T>& S){T ret = *S.rbegin();S.erase(S.rbegin());return ret;} template<class T> T peek(set<T>& S){T ret = *S.begin();return ret;} template<class T> T peek(mset<T>& S){T ret = *S.begin();return ret;} template<class T> T peek_back(set<T>& S){T ret = *S.rbegin();return ret;} template<class T> T peek_back(mset<T>& S){T ret = *S.rbegin();return ret;} vector<string> split(const string a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;} vector<string> split(const string a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;} ll stoi(string& s){return stol(s);} void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0);} void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0);} void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0);} void fAb(bool a) { if(a)cout<<"Alice"<<endl;else cout<<"Bob";} void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);} void POSSIBLE(bool a) { if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);} void fPossible(bool a) { Possible(a);exit(0);} void fPOSSIBLE(bool a) { POSSIBLE(a);exit(0);} template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; } //未分類 //0,2,1 1番目と2番目の次元を入れ替える template<class T> auto irekae(vector<vector<vector<T> > > &A, int x, int y, int z) { #define irekae_resize_loop(a, b, c) resize(res,a,b,c);rep(i,a)rep(j,b)rep(k,c) vector<vector<vector<T> > > res; if (x == 0 && y == 1 && z == 2) { res = A; } else if (x == 0 && y == 2 && z == 1) { irekae_resize_loop(sz(A), sz(A[0][0]), sz(A[0])) { res[i][j][k] = A[i][k][j]; } } else if (x == 1 && y == 0 && z == 2) { irekae_resize_loop(sz(A[0]), sz(A), sz(A[0][0])) { res[i][j][k] = A[j][i][k]; } } else if (x == 1 && y == 2 && z == 0) { irekae_resize_loop(sz(A[0]), sz(A[0][0]), sz(A)) { res[i][j][k] = A[k][i][j]; } } else if (x == 2 && y == 0 && z == 1) { irekae_resize_loop(sz(A[0][0]), sz(A), sz(A[0])) { res[i][j][k] = A[j][k][i]; } } else if (x == 2 && y == 1 && z == 0) { irekae_resize_loop(sz(A[0][0]), sz(A[0]), sz(A)) { res[i][j][k] = A[k][j][i]; } } return res; #undef irekae_resize_loop } template<class T> auto irekae(vector<vector<T>>&A,int i=1,int j=0){ vvt(res,sz(A[0]),sz(A)); rep(i,sz(A)){ rep(j,sz(A[0])){ res[j][i]=A[i][j]; } } return res;} //tou分割する template<typename T> vector<vector<T>> cut(vector<T> &a, int tou = 2) { int N = sz(a); vector<vector<T>> res(tou); int hab = N / tou; vi lens(tou, hab); rep(i, N % tou) { lens[tou - 1 - i]++; } int l = 0; rep(i, tou) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;} //長さn毎に分割する template<typename T> vector<vector<T>> cutn(vector<T> &a, int len) { int N = sz(a); vector<vector<T>> res(ceil(N, len)); vi lens(N / len, len); if (N % len)lens.push_back(N % len); int l = 0; rep(i, sz(lens)) { int len = lens[i]; int r = l + len; res[i].resize(len); std::copy(a.begin() + l, a.begin() + r, res[i].begin()); l = r; } return res;} vi inds_(vi &a) { int n = sz(a); vb was(n); vi res(n); rep(i, n) { assert(!was[a[i]]); res[a[i]] = i; was[a[i]] = true; } return res;} //@起動時 struct initon { initon() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); srand((unsigned) clock() + (unsigned) time(NULL)); }; } initonv; #define pre prev #define nex next //gra mll pr //上下左右 const string udlr = "udlr"; string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0] //右、上が正 constexpr ll h4[] = {1, -1, 0, 0}; constexpr ll w4[] = {0, 0, -1, 1}; constexpr ll h8[] = {0, 1, 0, -1, -1, 1, 1, -1}; constexpr ll w8[] = {1, 0, -1, 0, 1, -1, 1, -1}; int mei_inc(int h, int w, int H, int W, int i) {while (++i < 4) { if (inside(h + h4[i], w + w4[i], H, W))return i; }return i;} #define mei(nh, nw, h, w) for (int i = mei_inc(h, w, H, W, -1), nh = i<4? h + h4[i] : 0, nw = i<4? w + w4[i] : 0; i < 4; i=mei_inc(h,w,H,W,i), nh = h+h4[i], nw = w+w4[i]) //グラフ内で #undef getid //#define getidとしているため、ここを書き直したらgraphも書き直す #define getid_2(h, w) (h * W + w) #define getid_1(p) (p.first * W + p.second) #define getid(...) over2(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__) #define getp(id) mp(id / W, id % W) //#define set_shuffle() std::random_device seed_gen;std::mt19937 engine(seed_gen()) //#define shuffle(a) std::shuffle((a).begin(), (a).end(), engine); //1980 開始からtime ms経っていたらtrue bool timeup(int time) { auto end_time = system_clock::now(); auto part = duration_cast<milliseconds>(end_time - start_time); auto lim = milliseconds(time); return part >= lim; } void set_time() { past_time = system_clock::now(); } //MS型(millisecqnds)で返る //set_timeをしてからの時間 auto calc_time_milli() { auto now = system_clock::now(); auto part = duration_cast<milliseconds>(now - past_time); return part;} auto calc_time_micro() { auto now = system_clock::now(); auto part = duration_cast<microseconds>(now - past_time); return part;} auto calc_time_nano() { auto now = system_clock::now(); auto part = duration_cast<nanoseconds>(now - past_time); return part;} bool calc_time(int zikan) { return calc_time_micro() >= microseconds(zikan); } using MS=std::chrono::microseconds; int div(microseconds a, microseconds b) { return a / b; } int div(nanoseconds a, nanoseconds b) { if (b < nanoseconds(1)) { return a / nanoseconds(1); } int v = a / b; return v;} //set_time(); //rep(i,lim)shori //lim*=time_nanbai(); //rep(i,lim)shoriと使う //全体でmilliかかっていいときにlimを何倍してもう一回できるかを返す int time_nanbai(int milli) { auto dec = duration_cast<nanoseconds>(past_time - start_time); auto part = calc_time_nano(); auto can_time = nanoseconds(milli * 1000 * 1000); can_time -= part; can_time -= dec; return div(can_time, part); } /*@formatter:on*/ //vectorで取れる要素数 //bool=> 1e9 * 8.32 //int => 1e8 * 2.6 //ll => 1e8 * 1.3 //3次元以上取るとメモリがヤバい //static配列を使う vvc (ba); ll N, M, H, W; vi A, B, C; #undef getid /*@formatter:off*/ #define forg(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi) #define fort(gi, ve) for (ll gi = 0, f, t, c,wasp = (p != -1 && ve[gi].t == p) ? 1 : 0; (wasp = wasp ? 1 : (p != -1 && ve[gi].t == p) ? 1 : 0,gi + wasp < ve.size()) &&(tie(f, t, c) = wasp ? make_tuple(ve[gi + 1].f, ve[gi + 1].t, ve[gi + 1].c) : make_tuple(ve[gi].f, ve[gi].t, ve[gi].c), true); ++gi) #define fore(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi) template<class T> struct edge_ { int f, t; T c; edge_(int f, int t, T c = 1) : f(f), t(t), c(c) {} bool operator<(const edge_ &b) const { return c < b.c; } bool operator>(const edge_ &b) const { return c > b.c; }}; template<class T> ostream &operator<<(ostream &os, edge_<T> &e) {os << e.f << " " << e.t << " " << e.c;return os;} template<typename T> class graph { public : vector<vector<edge_<T>>> g; vector<edge_<T>> edges; int n; explicit graph(int n) : n(n) { g.resize(n); } void clear() { g.clear(), edges.clear(); } void resize(int n) {this->n = n;g.resize(n);} int size() { return n; } vector<edge_<T> > &operator[](int i) { return g[i]; } virtual void add(int f, int t, T c) = 0; virtual void set_edges() = 0; }; template<typename T =ll> class digraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; explicit digraph(int n) : graph<T>(n) {} void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) {debugline("digraph add");deb(f, t, c);ole();} g[f].emplace_back(f, t, c); edges.emplace_back(f, t, c);//edgesを使わないなら消せる } void ing(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t; cin >> f >> t; f -= minus; t -= minus; add(f, t); } } void ingc(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t, c; cin >> f >> t >> c; f -= minus; t -= minus; add(f, t, c); } } void set_edges() override{ if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); } }; template<class T=int> class undigraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; explicit undigraph(int n) : graph<T>(n) {} // f < t void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("undigraph add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); g[t].emplace_back(t, f, c); edges.emplace_back(f, t, c);//edgesを使わないなら消せる edges.emplace_back(t, f, c); } void add(edge_<T> &e) { int f = e.f, t = e.t; T c = e.c; add(f, t, c); } void ing(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t; cin >> f >> t; f -= minus; t -= minus; add(f, t); } } void ingc(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t, c; cin >> f >> t >> c; f -= minus; t -= minus; add(f, t, c); } } void set_edges () override{ if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); } }; #define dijkstra_path dis_path template<class T> vi dis_path(digraph<T> &g, vector<T> &dis, int s, int t, int init_value) { assert(dis[t] != init_value); auto rg = rev(g); int now = t; vi path; path.push_back(now); T cost = 0; while (now != s) { rep(gi, sz(rg[now])) { int m = rg[now][gi].t; if (dis[m] == init_value)continue; if (dis[m] + rg[now][gi].c + cost == dis[t]) { cost += rg[now][gi].c; now = m; break; } } path.push_back(now); } rev(path); return path;} template<class T> vi dis_path(undigraph<T> &g, vector<T> &dis, int s, int t, int init_value) { assert(dis[t] != init_value); int now = t; vi path; path.push_back(now); T cost = 0; while (now != s) { rep(gi, sz(g[now])) { int m = g[now][gi].t; if (dis[m] == init_value)continue; if (dis[m] + g[now][gi].c + cost == dis[t]) { cost += g[now][gi].c; now = m; break; } } path.push_back(now); } rev(path); return path;} template<class T> vi dis_path(digraph<T> &g, vector<vector<T>> &dis, int s, int t, int init_value) { return dis_path(g, dis[s], s, t, init_value); } template<class T> vi dis_path(undigraph<T> &g, vector<vector<T>> &dis, int s, int t, int init_value) { return dis_path(g, dis[s], s, t, init_value); } //O(N^2) template<class T> vector<T> dijkstra_mitu(graph<T> &g, int s, int init_value) { if (!(0 <= s && s < g.n)) { debugline("dijkstra_mitu"); deb(s, g.n); ole(); } int n = g.n; int initValue = MAX(int); vector<T> dis(n, initValue); dis[s] = 0; vb used(n); while (true) { int v = -1; rep(u, n) { if (!used[u] && (v == -1 || dis[u] < dis[v]))v = u; } if (v == -1)break; if (dis[v] == initValue)break; used[v] = true; rep(u, sz(g[v])) { auto e = g[v][u]; dis[e.t] = min(dis[e.t], dis[v] + e.c); } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) { if (d == initValue) { d = init_value; }} return dis;} template<typename T> struct radixheap { vector<pair<u64, T> > v[65]; u64 size, last; radixheap() : size(0), last(0) {} bool empty() const { return size == 0; } int getbit(int a) { return a ? 64 - __builtin_clzll(a) : 0; } void push(u64 key, const T &value) { ++size; v[getbit(key ^ last)].emplace_back(key, value); } pair<u64, T> pop() { if (v[0].empty()) { int idx = 1; while (v[idx].empty()) ++idx; last = min_element(begin(v[idx]), end(v[idx]))->first; for (auto &p : v[idx]) v[getbit(p.first ^ last)].emplace_back(p); v[idx].clear(); } --size; auto ret = v[0].back(); v[0].pop_back(); return ret; }}; /*radix_heap こっちの方が早い*/ //O((N+M) log N) vi dijkstra(graph<int> &g, int s, int init_value) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } /*O((N+M) log N) vs O(N^2)*/ if ((g.n + sz(g.edges)) * log2(N) > g.n * g.n) { return dijkstra_mitu(g, s, init_value); } int initValue = MAX(int); vi dis(g.n, initValue); radixheap<int> q; dis[s] = 0; q.push(0, s); while (!q.empty()) { int nowc, i; tie(nowc, i) = q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; int c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.push(dis[to], to); } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return dis;} template<class T> vector<T> dijkstra_normal(graph<T> &g, int s, int init_value) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } if ((g.n + sz(g.edges)) * 20 > g.n * g.n) { return dijkstra_mitu(g, s, init_value); } T initValue = MAX(T); vector<T> dis(g.n, initValue); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.emplace(dis[to], to); } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return dis;} template<class T> vector<T> dijkstra_01(graph<T> &g, int s, int init_value) { int N = g.n; vi dis(N, linf); dis[s] = 0; deque<int> q; q.push_back(s); vb was(N); while (!q.empty()) { int f = q.front(); q.pop_front(); if (was[f])continue; was[f] = true; fora(e, g[f]) { if (dis[e.t] > dis[f] + e.c) { if (e.c) { dis[e.t] = dis[f] + 1; q.push_back(e.t); } else { dis[e.t] = dis[f]; q.push_front(e.t); } } } } rep(i, N)if(dis[i]==linf)dis[i]=init_value; return dis;} //dijkstra_cou<mint> : 数える型で書く return vp(dis,cou) template<class COU,class T=int> auto dijkstra_cou(const graph<T> &g, int s, int init_value) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } err("count by type COU "); err("int or mint"); T initValue = MAX(T); vector<T> dis(g.n, initValue); vector<COU> cou(g.n); cou[s] = 1; priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; cou[to] = cou[e.f]; q.emplace(dis[to], to); } else if (dis[to] == c) { cou[to] += cou[e.f]; } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return vtop(dis, cou);} //密グラフの時、warshallに投げる template<class T> vector<vector<T>> dijkstra_all(const graph<T> &g, int init_value) {int n = g.n;assert(n < 1e4);if (n * n < (n + sz(g.edges)) * 14) { /*O(N^3) vs O(N (N+M)log N)*/ return warshall(g, init_value); }vector<vector<T>> dis(n);rep(i, n) { dis[i] = dijkstra(g, i, init_value); }return dis;} //コストを無限に減らせる := -linf //たどり着けない := linf template<class T> vector<T> bell(graph<T> &g, int s) { if (g.n >= 1e4) { cout << "bell size too big" << endl; exit(0); } vector<T> res(g.n, linf); res[s] = 0; vb can(g.n); /*頂点から行けない頂点を持つ、辺を消しておく */ fix([&](auto ds, int p, int i) -> void { if (can[i])return; can[i] = true; forg(gi, g[i])if (t != p)ds(i, t); })(-1, 0); vector<edge_<T>> es; fora(e, g.edges) { if (can[e.f])es += e; } rep(i, g.n) { bool upd = false; fora(e, es) { if (res[e.f] != linf && res[e.t] > res[e.f] + e.c) { upd = true; res[e.t] = res[e.f] + e.c; } } if (!upd)break; } rep(i, g.n * 2) { bool upd = 0; fora(e, g.edges) { if (res[e.f] != linf && res[e.t] != -linf && res[e.t] > res[e.f] + e.c) { upd = 1; res[e.t] = -linf; } } if (!upd)break; } return res;} //コストを無限に増やせる := linf //たどり着けない := -linf template<class T> vector<T> bell_far(graph<T> &g, int s) { if (g.n >= 1e4) { cout << "bell_far size too big" << endl; exit(0); } vector<T> res(g.n, linf); res[s] = 0; vb can(g.n); /*頂点から行けない頂点を持つ、辺を消しておく*/ fix([&](auto ds, int p, int i) -> void { if (can[i])return; can[i] = true; forg(gi, g[i])if (t != p)ds(i, t); })(-1, 0); vector<edge_<T>> es; fora(e, g.edges) { if (can[e.f])es += e; } rep(i, g.n) { bool upd = false; fora(e, es) { if (res[e.f] != linf && res[e.t] > res[e.f] - e.c) {/*-c*/ upd = true; res[e.t] = res[e.f] - e.c;/*-c*/ } } if (!upd)break; } rep(i, g.n * 2) { bool upd = 0; fora(e, g.edges) { if (res[e.f] != linf && res[e.t] != -linf && res[e.t] > res[e.f] - e.c) {/*-c*/ upd = 1; res[e.t] = -linf; } } if (!upd)break; } rep(i, g.n)res[i] *= -1; return res;} template<class T> vector<vector<T>> warshall(graph<T> &g, int init_value) { int n = g.n; assert(n < 1e4); vector<vector<T> > dis(n, vector<T>(n, linf)); rep(i, n)fora(e, g.g[i]) { if (dis[e.f][e.t] > e.c) { dis[e.f][e.t] = e.c; } } rep(i, n)dis[i][i] = 0; rep(k, n) rep(i, n) rep(j, n) { if (dis[i][j] > dis[i][k] + dis[k][j]) { dis[i][j] = dis[i][k] + dis[k][j]; } } rep(i, n)rep(j, n) if (dis[i][j] == linf)dis[i][j] = init_value; return dis;} template<class T> class MinOp { public: T operator()(T a, T b) { return min(a, b); }}; template<typename OpFunc> struct SparseTable { OpFunc op; signed size; vector<signed> lg; vector<vector<pair<signed, signed>>> table; void init( vector<pair<signed, signed>> &array, OpFunc opfunc) { signed n = array.size(); op = opfunc; lg.assign(n + 1, 0); for (signed i = 1; i <= n; i++) { lg[i] = 31 - __builtin_clz(i); } table.assign(lg[n] + 1, array); for (signed i = 1; i <= lg[n]; i++) { for (signed j = 0; j < n; j++) { if (j + (1 << (i - 1)) < n) { table[i][j] = op(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]); } else { table[i][j] = table[i - 1][j]; }}} } pair<signed, signed> query(signed l, signed r) { assert(l < r); return op(table[lg[r - l]][l], table[lg[r - l]][r - (1 << lg[r - l])]); }}; struct PMORMQ { vector<signed> a; SparseTable<MinOp<pair<signed, signed> > > sparse_table; vector<vector<vector<signed> > > lookup_table; vector<signed> block_type; signed block_size, n_block; void init( vector<signed> &array) { a = array; signed n = a.size(); block_size = std::max(1, (31 - __builtin_clz(n)) / 2); while (n % block_size != 0) { a.push_back(a.back() + 1); n++; } n_block = n / block_size; vector<pair<signed, signed> > b(n_block, make_pair(INT_MAX, INT_MAX)); for (signed i = 0; i < n; i++) { b[i / block_size] = min(b[i / block_size], make_pair(a[i], i)); } sparse_table.init(b, MinOp<pair<signed, signed> >()); block_type.assign(n_block, 0); for (signed i = 0; i < n_block; i++) { signed cur = 0; for (signed j = 0; j < block_size - 1; j++) { signed ind = i * block_size + j; if (a[ind] < a[ind + 1]) { cur |= 1 << j; } } block_type[i] = cur; } lookup_table.assign(1 << (block_size - 1), vector<vector<signed> >(block_size, vector<signed>(block_size + 1))); for (signed i = 0; i < (1 << (block_size - 1)); i++) { for (signed j = 0; j < block_size; j++) { signed res = 0; signed cur = 0; signed pos = j; for (signed k = j + 1; k <= block_size; k++) { lookup_table[i][j][k] = pos; if (i & (1 << (k - 1))) { cur++; } else { cur--; } if (res > cur) { pos = k; res = cur; } } } } } signed query(signed l, signed r) { assert(l < r); signed lb = l / block_size; signed rb = r / block_size; if (lb == rb) { return lb * block_size + lookup_table[block_type[lb]][l % block_size][r % block_size]; } signed pl = lb * block_size + lookup_table[block_type[lb]][l % block_size][block_size]; signed pr = rb * block_size + lookup_table[block_type[rb]][0][r % block_size]; signed pos = pl; if (r % block_size > 0 && a[pl] > a[pr]) { pos = pr; } if (lb + 1 == rb) { return pos; } signed spv = sparse_table.query(lb + 1, rb).second; if (a[pos] > a[spv]) { return spv; } return pos; }}; template<class T=int> class tree : public undigraph<T> { PMORMQ rmq; int cnt; vector<signed> id, in; bool never = true; bool never_hld = true; void dfs(int x, int p, int d, int dis = 0) { id[cnt] = x; par_[x] = p; rmq_dep.push_back(d); disv[x] = dis; in[x] = cnt++; forg(gi, g[x]) { if (t == p) { continue; } dfs(t, x, d + 1, dis + c); id[cnt] = x; rmq_dep.push_back(d); cnt++; } } void precalc() { never = false; cnt = 0; rmq_dep.clear(); disv.assign(n, 0); in.assign(n, -1); id.assign(2 * n - 1, -1); par_.assign(n, -1); dfs(root, -1, 0); rmq.init(rmq_dep); #ifdef _DEBUG if(n>=100)return;cerr << "---tree---" << endl; rep(i, n) { if (!(i == root || sz(g[i]) > 1))continue; cerr << i << " -> "; vi ts; forg(gi, g[i]) { if (t != par_[i])ts.push_back(t); } rep(i, sz(ts) - 1)cerr << ts[i] << ", "; if(sz(ts))cerr << ts.back() << endl; } cerr << endl; #endif } int pos; void hld_build() { never_hld = false; if (never)precalc(); g.resize(n); vid.resize(n, -1); head.resize(n); heavy.resize(n, -1); depth.resize(n); inv.resize(n); subl.resize(n); subr.resize(n); dfs(root, -1); t = 0; dfs_hld(root); #ifdef _DEBUG if (n >= 100)return; cerr << "---hld_index---" << endl; vi inds; rep(i, n) if (sz(g[i]))inds.push_back(i); rep(i, sz(inds)) { str s = tos(bel(inds[i])); cerr << std::right << std::setw(sz(s) + (i ? 1 : 0)) << inds[i]; } cerr << endl; rep(i, sz(inds)) { cerr << bel(inds[i]) << " "; } cerr << endl << endl; cerr << "---hld_edge_index---" << endl; fora(e, edges) { if (e.f <= e.t) cerr << e.f << "-" << e.t << " " << bel(e) << endl; } cerr << endl << endl; cerr << "!!query!! edge or not edge carefull!!" << endl; #endif } int dfs(int curr, int prev) { int sub = 1, max_sub = 0; heavy[curr] = -1; forg(i, g[curr]) { int next = t; if (next != prev) { depth[next] = depth[curr] + 1; int sub_next = dfs(next, curr); sub += sub_next; if (max_sub < sub_next) max_sub = sub_next, heavy[curr] = next; } } return sub; } int t = 0; #ifndef __CLION_IDE__ void dfs_hld(int v = 0) { vid[v] = subl[v] = t; t++; inv[subl[v]] = v; if (0 <= heavy[v]) { head[heavy[v]] = head[v]; dfs_hld(heavy[v]); } forg(i, g[v])if (depth[v] < depth[t]) if (t != heavy[v]) { head[t] = t; dfs_hld(t); } subr[v] = t; } #endif//__CLION_IDE__ vector<signed> rmq_dep; vi par_, depth, disv; vi childs; vi par_id_;//親への辺のidを持つ vvi(ids_);//隣接で辺のidを持つ public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; int root; //(f,t)と(t,f)は同じidを持ち、[0,n-1]でadd順に割り振られる //部分木の [左端、右端) index //部分木の辺に加算する場合 //add(subl[i],subr[i],x) //add(sub[i],sub[i+1],-x) vector<int> vid, head, heavy, inv, subl, subr; tree(int n_, int root = 0) : undigraph<T>(n_), root(root) { n = n_; } void root_change(int roo){root = roo;precalc();} //葉になりえない頂点を根にする void root_change_mid(){ message+="N>2 (mid)\n"; assert(n>2); rep(i, n){ if(sz(g[i])>1){ root_change(i); return; } } } int lca(int a, int b) { if (never)precalc(); int x = in[a]; int y = in[b]; if (x > y) { swap(x, y); } int pos = rmq.query(x, y + 1); return id[pos]; } int dis(int a, int b) { if (never)precalc(); int x = in[a]; int y = in[b]; if (x > y) { swap(x, y); } int pos = rmq.query(x, y + 1); int p = id[pos]; return disv[a] + disv[b] - disv[p] * 2; } int dep(int a){if (never)precalc(); return disv[a];} int par(int a){if (never)precalc(); return par_[a];} bool isleaf(int i){if(never)precalc();return(sz(g[i])==1 && i!=root);} bool leaf(int i){return isleaf(i);} vi child(int r) { vi res; res.push_back(r); queue<int> q; q.push(r); while (!q.empty()) { int i = q.front(); res.push_back(i); q.pop(); forg(gi, g[i]) { if (t != par(i))q.push(t); } } return res; } vb child_ex(int r) { vb res(n); res[r] = true; queue<int> q; q.push(r); while (!q.empty()) { int i = q.front(); res[i] = true; q.pop(); forg(gi, g[i]) { if (t != par(i))q.push(t); } } return res; }int dfs_count_subtree(int p,int i){ childs[i] =1; fort(gi, g[i]){ childs[i] += dfs_count_subtree(i,t); } return childs[i]; } #define count_child count_subtree int count_subtree(int f){ if(sz(childs)==0){ if(never)precalc(); childs.resize(n); dfs_count_subtree(-1,root); } return childs[f]; } //fからtの辺を切った時のtの大きさ int count_subtree(int f,int t){ if(par(f)==t) { return n - count_subtree(f); }else{ return count_subtree(t); } } vi path(int a, int b) { vi res; for_each_l(a, b, [&](int i) { res.push_back(i); }); return res; } //idはedgesに使えない ↓edge(id)とする //pathに含まれる辺のid達を返す vi pathe(int a,int b){ #ifdef _DEBUG static bool was = 0;if(!was)message+="can't edges[id]. must edge(id)\n";was=1; #endif if(sz(par_id_)==0){ ids_.resize(n); par_id_.resize(n); rep(i,0,sz(edges),2){ ids_[edges[i].f].emplace_back(i>>1); ids_[edges[i].t].emplace_back(i>>1); } if(never)precalc();/*par_を呼ぶため*/ rep(i, n){ int pa = par_[i]; forg(gi, g[i]){ if(t==pa){ par_id_[i] = ids_[i][gi]; } } } } int u = lca(a,b); vi res; if (a != u) { do { res.emplace_back(par_id_[a]); a = par_[a]; } while (a != u); } vi rev; if (b != u) { do { rev.emplace_back(par_id_[b]); b = par_[b]; } while (b != u); } rer(i,sz(rev)-1){ res.emplace_back(rev[i]); } return res; } //親の辺のidを返す int par_id(int i){if(sz(par_id_)==0){pathe(0,0);}return par_id_[i];} //fのi番目の辺のidを返す int ids(int f,int i) {if(sz(ids_)==0){pathe(0,0);}return ids_[f][i];} //idから辺を返す edge_<T> edge(int id){return edges[id<<1];} /*O(N) hldを使わず木を普通にたどる liteの意*/ void for_each_l(int u, int v, function<void(int)> fnode) { int r = lca(u, v); while (u != r) { fnode(u); u = par_[u]; } fnode(r); vi a; while (v != r) { a.push_back(v); v = par_[v]; } while(sz(a)){ fnode(a.back()); a.pop_back(); } } void for_each_edge_l(int u, int v, function<void(edge_<int> &)> fedge) { int r = lca(u, v); while (u != r) { forg(gi, g[u]) { if (t == par_[u]) { fedge(g[u][gi]); u = par_[u]; break; } } } vector<edge_<int>> qs; while (v != r) { forg(gi, g[v]) { if (t == par_[v]) { qs.push_back(g[v][gi]); v = par_[v]; break; } } } while(sz(qs)){ fedge(qs.back()); qs.pop_back(); } } //Fは半開 (u,v)は木の頂点 //中ではhldの頂点を見るため、seg木のupdateはhldのindexで行なう void for_each_/*[l,r)*/(int u, int v, const function<void(int, int)> &f) { if (never_hld)hld_build(); while (1) { if (vid[u] > vid[v]) swap(u, v); int l = max(vid[head[v]], vid[u]); int r = vid[v] + 1; f(l, r); if (head[u] != head[v]) v = par_[head[v]]; else break; } } void for_each_edge/*[l,r) O(log(N)) 辺を頂点として扱っている 上と同じ感じで使える*/(int u, int v, const function<void(int, int)> &f) { if (never_hld)hld_build(); while (1) { if (vid[u] > vid[v]) swap(u, v); if (head[u] != head[v]) { int l = vid[head[v]]; int r = vid[v] + 1; f(l, r); v = par_[head[v]]; } else { if (u != v) { int l = vid[u] + 1; int r = vid[v] + 1; f(l, r); } break; } } } int bel(int v) { /*hld内での頂点番号を返す*/ if (never_hld)hld_build();return vid[v];} //下の頂点に辺のクエリを持たせている int bel(int f, int t) { /*辺のクエリを扱うときどの頂点に持たせればいいか(vidを返すのでそのままupd出来る)*/ if (never_hld)hld_build();return depth[f] > depth[t] ? vid[f] : vid[t];} int bel(edge_<T> &e) { /*辺のクエリを扱うときどの頂点に持たせればいいか(vidを返すのでそのままupd出来る)*/ if (never_hld)hld_build();return depth[e.f] > depth[e.t] ? vid[e.f] : vid[e.t];} template<class ... U> int operator()(U ... args) { return bel(args...); } //path l -> r += v template<class S> void seg_add(S &seg, int lhei, int rhei, int v) {for_each_(lhei, rhei, [&](int l, int r) { seg.add(l, r, v); });} template<class S> void seg_update(S &seg, int lhei, int rhei, int v) {for_each_(lhei, rhei, [&](int l, int r) { seg.update(l, r, v); });} template<class S> T seg_get(S &seg, int lhei, int rhei) { T res = seg.e; for_each_(lhei, rhei, [&](int l, int r) { res = seg.f(res, seg.get(l, r)); }); return res; } template<class S> void seg_add_edge(S &seg, int lhei, int rhei, int v) { for_each_edge(lhei, rhei, [&](int l, int r) { seg.add(l, r, v); }); } template<class S> void seg_update_edge(S &seg, int lhei, int rhei, int v) { for_each_edge(lhei, rhei, [&](int l, int r) { seg.update(l, r, v); }); } template<class S> T seg_get_edge(S &seg, int lhei, int rhei) { T res = seg.e; for_each_edge(lhei, rhei, [&](int l, int r) { res = seg.f(res, seg.get(l, r)); }); return res; } //単体 edgeは上で処理できる template<class S> void seg_add(S &seg, int i, int v) { seg.add(bel(i), v); } template<class S> void seg_update(S &seg, int i, int v) { seg.update(bel(i), v); } template<class S> T seg_get(S &seg, int i) { return seg[i]; } template<class S> void seg_del(S &seg, int i) { seg.del(bel(i)); } //部分木iに対するクエリ template<class S> void seg_add_sub(S &seg, int i, int v) {if (never_hld)hld_build();seg.add(subl[i], subr[i], v);} template<class S> void seg_update_sub(S &seg, int i, int v) {if (never_hld)hld_build();seg.update(subl[i], subr[i], v);} template<class S> T seg_get_sub(S &seg, int i, int v) {if (never_hld)hld_build();return seg.get(subl[i], subr[i], v);} template<class S> void seg_add_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/seg.add(subl[i] + 1, subr[i], v);} template<class S> void seg_update_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/seg.update(subl[i] + 1, subr[i], v);} template<class S> T seg_get_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/return seg.get(subl[i] + 1, subr[i], v);} }; //辺が多いのでedgesを持たない //cost oo, ox, xo, xx 渡す template<class T=int> class grid_k6 : public undigraph<T> { vi costs; public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; int H, W; vector<vector<char>> ba; char wall; void add(int f, int t, T c = 1){ if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("grid_k6 add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); g[t].emplace_back(t, f, c); //undigraphと違い、edgesを持たない } int getid(int h, int w) { assert(ins(h, w, H, W)); return W * h + w; } int getid(P p) { return getid(p.first, p.second); } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } int operator()(P p) { return getid(p); } //辺は無い grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {} grid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } /*o -> o, o -> x, x -> o, x-> x*/ grid_k6(vector<vector<char>> ba, int oo, int ox, int xo, int xx, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])), costs({oo, ox, xo, xx}), ba(ba), wall(wall) { rep(h, H) { rep(w, W) { add(h, w, h + 1, w); add(h, w, h - 1, w); add(h, w, h, w + 1); add(h, w, h, w - 1); } } } void add(int fh, int fw, int th, int tw) { if (ins(fh, fw, H, W) && ins(th, tw, H, W)) { int cm = 0; if (ba[fh][fw] == wall) { cm += 2; } if (ba[th][tw] == wall) { cm++; } int f = getid(fh, fw); int t = getid(th, tw); g[f].emplace_back(f, t, costs[cm]); } } void set_edges() { rep(i, n)fora(e, g[i])if (e.f < e.t)edges.push_back(e); } }; //辺によりメモリを大量消費ためedgesを消している //頂点10^6でメモリを190MB(制限の8割)使う //左上から右下に移動できる template<class T=int> class digrid_k6 : public digraph<T> { public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; int H, W; void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digrid_k6 add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); /*digraphと違いedgesを持たない*/ } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W){} digrid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); } }; //edgesを持たない //dijkstra(g,0)[t] とかける (t+n-1等とする必要はない) template<class T=int>class segdi : public digraph<T>{int getid(int k){ if(k >= len*2-1){ return k; } else if(k < len - 1){ return k + len; }else{ return k - len + 1; } }void add(int f, int t, T c = 1) { f = getid(f); t = getid(t); if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("segdi add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); /*digraphと違いedgesを持たない*/ }int mid;int len; public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; //頂点が足りなくなったらresize segdi(int n_) : digraph<T>(1) { int nn = 1; while (nn < n_)nn *= 2; n_ = nn; len = n_; this->resize(n_ + (n_ - 1) * 2 + n_); mid = n_ + (n_ - 1) * 2; int ad = len * 2 - 1; rep(i, len - 1) { add(i, i * 2 + 1, 0); add(i, i * 2 + 2, 0); if (i * 2 + 1 >= len - 1) { add(i * 2 + 1, i + ad, 0); add(i * 2 + 2, i + ad, 0); } else { add(i * 2 + 1 + ad, i + ad, 0); add(i * 2 + 2 + ad, i + ad, 0); } } } void dfs(vi &list, int nl, int nr, int k, int l, int r) { if (r <= nl || nr <= l)return; if (l <= nl && nr <= r) { list += k; } else { dfs(list, nl, (nl + nr) / 2, k * 2 + 1, l, r); dfs(list, (nl + nr) / 2, nr, k * 2 + 2, l, r); } } void rekkyo(vi &list, int l, int r) { l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { list.push_back(l); } if (!(r & 1)) { list.push_back(r - 1); } l >>= 1; r = (r - 1) >> 1; } } //半開 void add(int fl, int fr, int tl, int tr, int cost) { /*fは下側*/ int ad = 2 * len - 1; if (mid >= n) { this->resize(n + 100); } { int l = fl, r = fr; l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { if (l - len + 1 < 0)add(l + ad, mid, cost); else add(l, mid, cost); } if (!(r & 1)) { if (r - 1 - len + 1 < 0)add(r - 1 + ad, mid, cost); else add(r - 1, mid, cost); } l >>= 1; r = (r - 1) >> 1; } } { int l = tl, r = tr; l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { add(mid, l, 0); } if (!(r & 1)) { add(mid, r - 1, 0); } l >>= 1; r = (r - 1) >> 1; } } mid++; } }; //edgesを持たない //dijkstra(g,0)[t] とかける (t+n-1等とする必要はない) template<class T=int>class segun : public undigraph<T>{int getid(int k){ if(k >= len*2-1){ return k; } else if(k < len - 1){ return k + len; }else{ return k - len + 1; } }void add(int f, int t, T c = 1) { f = getid(f); t = getid(t); if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("segun add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); /*digraphと違いedgesを持たない*/ g[t].emplace_back(t, f, c); /*digraphと違いedgesを持たない*/ } int mid; int len; public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; //頂点が足りなくなったらresize segun(int n_) : digraph<T>(1) { int nn = 1; while (nn < n_)nn *= 2; n_ = nn; len = n_; this->resize(n_ + (n_ - 1) * 2 + n_); mid = n_ + (n_ - 1) * 2; int ad = len * 2 - 1; rep(i, len - 1) { add(i, i * 2 + 1, 0); add(i, i * 2 + 2, 0); if (i * 2 + 1 >= len - 1) { add(i * 2 + 1, i + ad, 0); add(i * 2 + 2, i + ad, 0); } else { add(i * 2 + 1 + ad, i + ad, 0); add(i * 2 + 2 + ad, i + ad, 0); } } } void dfs(vi &list, int nl, int nr, int k, int l, int r) { if (r <= nl || nr <= l)return; if (l <= nl && nr <= r) { list += k; } else { dfs(list, nl, (nl + nr) / 2, k * 2 + 1, l, r); dfs(list, (nl + nr) / 2, nr, k * 2 + 2, l, r); } } void rekkyo(vi &list, int l, int r) { l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { list.push_back(l); } if (!(r & 1)) { list.push_back(r - 1); } l >>= 1; r = (r - 1) >> 1; } } //半開 void add(int fl, int fr, int tl, int tr, int cost) { /*fは下側*/ int ad = 2 * len - 1; if (mid >= n) { this->resize(n + 100); } { int l = fl, r = fr; l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { if (l - len + 1 < 0)add(l + ad, mid, cost); else add(l, mid, cost); } if (!(r & 1)) { if (r - 1 - len + 1 < 0)add(r - 1 + ad, mid, cost); else add(r - 1, mid, cost); } l >>= 1; r = (r - 1) >> 1; } } { int l = tl, r = tr; l += len - 1; r += len - 1; while (l < r) { if (!(l & 1)) { add(mid, l, 0); } if (!(r & 1)) { add(mid, r - 1, 0); } l >>= 1; r = (r - 1) >> 1; } } mid++; } }; #define getid_2(h, w) (h * W + w) #define getid_1(p) (p.first * W + p.second) #define o_getid(a,b,name,...) name #define getid(...) o_getid(__VA_ARGS__, getid_2, getid_1) (__VA_ARGS__) #define unionfind unionfind_graph struct unionfind { vector<ll> par; vector<ll> siz; vector<ll> es; ll n, trees;//連結グループの数(親の種類) unionfind(ll n) : n(n), trees(n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } template<class T>unionfind(graph<T>& g) : n(g.n), trees(g.n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } add(g); } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }} ll operator()(ll x){return root(x);} bool unite(ll x, ll y) { x = root(x); y = root(y); es[x]++; if (x == y) return false; if (siz[x] > siz[y]) swap(x, y); trees--; par[x] = y; siz[y] += siz[x]; es[y] += es[x]; return true; } template<class T>void add(graph<T>&g){fora(e,g.edges){unite(e.f,e.t);}} template<class T>void unite(graph<T>&g){add(g);} bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } ll esize(ll x) { return es[root(x)]; } vi sizes(){ vi cou(n); vi ret; ret.reserve(n); rep(i, n){ cou[root (i)]++; } rep(i, n){ if(cou[i])ret.push_back(cou[i]); } return ret; } //つながりを無向グラフと見なし、xが閉路に含まれるか判定 bool close(ll x) { return esize(x) >= size(x); } vector<vi> sets() { vi ind(n, -1); ll i = 0; vvi(res, trees); rep(j, n) { ll r = root(j); if (ind[r] == -1)ind[r] = i++; res[ind[r]].push_back(j); } rep(i, trees) { ll r = root(res[i][0]); if (res[i][0] == r)continue; rep(j, 1, sz(res[i])) { if (res[i][j] == r) { swap(res[i][0], res[i][j]); break; } } } return res; } };//@formatter:off //@出力 template<class T> ostream &operator<<(ostream &os, digraph<T> &g) { os << endl << g.n << " " << sz(g.edges) << endl; fore(gi, g.edges) { os << f << " " << t << " " << c << endl; } return os;}template<class T> ostream &operator<<(ostream &os, undigraph<T> &g) { os << endl << g.n << " " << sz(g.edges)/2 << endl; fore(gi, g.edges) { if (f < t)os << f << " " << t << " " << c << endl; } return os;} //@判定 template<class T> bool nibu( graph<T> &g) { int size = 0; rep(i, g.n)size += sz(g.g[i]); if (size == 0)return true; unionfind uf(g.n * 2); rep(i, g.n)fora(e, g.g[i])uf.unite(e.f, e.t + g.n), uf.unite(e.f + g.n, e.t); rep(i, g.n)if (uf.same(i, i + g.n))return 0; return true;} //頂点ではなく辺の数に依存した計算量 O(E) template<class T> bool nibu_sub( graph<T> &g) { umapi col;/*0なら無色 */ queue<int> q; /*色は01か11 */ fora(e, g.edegs) { /*fとtの色を持つか否かは同じ*/ if (col[e.f] == 0)q.push(e.f); while (!q.empty()) { int f = q.front(); q.pop(); int fc = col[f]; forg(gi, g[f]) { int &tc = col[t]; /*fcには色がある*/ if (fc == tc)return false; /*違う色*/ if (tc)continue; /*無色*/ tc = fc ^ 2; q.push(tc); } } } return true;} //二部グラフを色分けした際の頂点数を返す template<class T> vp nibug(graph<T> &g) { vp cg; if (!nibu(g)) { debugline("nibu"); ole(); } int n = g.size(); vb was(n); queue<P> q; rep(i, n) { if (was[i])continue; q.push(mp(i, 1)); was[i] = 1; int red = 0; int coun = 0; while (q.size()) { int now = q.front().fi; int col = q.front().se; red += col; coun++; q.pop(); forg(gi, g[now]) { if (was[t])continue; q.push(mp(t, col ^ 1)); was[t] = 1; } } cg.push_back(mp(red, coun - red)); } return cg;} //連結グラフが与えられる 閉路があるか template<class T> bool close(undigraph<T> &g) { int n = 0; int e = 0; rep(i, g.n) { if (sz(g[i]))n++; forg(gi, g[i]) { e++; } } return (e >> 1) >= n;} template<class T> bool close(undigraph<T> &g, int v) { unionfind uf(g.n); rep(i, g.n) { forg(gi, g[i]) { if (f < t)break; if (f == t && f == v)return true; if (uf.same(f, v) && uf.same(t, v))return true; uf.unite(f, t); } } return false;}template<class T> bool close(digraph<T> &g) { vi res; return topo(res, g);} //@変形 //条件(f!=0等 f,t,cが使える)を満たすsubgraphをg2に代入 #define sub_di(g, g2, zhouken) {g2.resize(g.n);fore(gi, g.edges){if(zhouken){g2.add(f,t,c);}}} #define sub_un(g, g2, zhouken) {g2.resize(g.n);fore(gi, g.edges){bool ok = zhouken; /*片方がアウトなら駄目という扱い*/swap(f,t); ok &= zhouken;if(ok && f < t){g2.add(f,t,c);}}} #define sub_tree sub_un //閉路がなければtrue bool topo(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; queue<int> st; rep(i, n)if (nyu[i] == 0)st.push(i); while (st.size()) { int v = st.front(); st.pop(); res.push_back(v); fora(e, g[v]) if (--nyu[e.t] == 0)st.push(e.t); } return res.size() == n;} //辞書順最小トポロジカルソート bool topos(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; /*小さい順*/ priority_queue<int, vector<int>, greater<int> > q; rep(i, n)if (nyu[i] == 0)q.push(i); while (q.size()) { int i = q.top(); q.pop(); res.push_back(i); fora(e, g[i])if (--nyu[e.t] == 0)q.push(e.t); } return res.size() == n;} template<class T> digraph<T> rev(digraph<T> &g) { digraph<T> r(g.n); rep(i, g.n) { forg(gi, g[i]) { r.add(t, f, c); }} return r;} //lc,rcは子を持つ中で一番左、右 //(g,ind,l,r) template<class T> tree<T> get_bfs_tree(tree<T> &g, vi &ind, vi &l, vi &r) {if (sz(ind)) {cerr << "ind must be empty" << endl;exit(0);}int N = sz(g);ind.resize(N);l.resize(N, inf);r.resize(N, -1);tree<T> h(N);queue<P> q;q.emplace(-1, 0);int c = 0;while (sz(q)) {int p = q.front().first;int i = q.front().second;q.pop();ind[i] = c;if (~p)chmi(l[ind[p]], c);if (~p)chma(r[ind[p]], c);c++;forg(gi, g[i]) {if (t != p)q.emplace(i, t);}}fora(e, g.edges) {if (e.f < e.t) {h.add(ind[e.f], ind[e.t], e.c);}}rep(i, N) {if (l[i] == inf)l[i] = -1;}return h;} //lc,rcは子を持つ中で一番左、右 // たとえばl[lc[x]は2段下の最左 //(g,ind,l,r,lc,rc) template<class T> tree<T> get_bfs_tree(tree<T> &g, vi &ind, vi &l, vi &r, vi &lc, vi &rc) { if (sz(ind)) { cerr << "ind must be empty" << endl; exit(0); } int N = sz(g); ind.resize(N); l.resize(N, inf); lc.resize(N, inf); r.resize(N, -1); rc.resize(N, -1); tree<T> h(N); queue<P> q; q.emplace(-1, 0); int c = 0; while (sz(q)) { int p = q.front().first; int i = q.front().second; q.pop(); ind[i] = c; if (~p) { chmi(l[ind[p]], c); chma(r[ind[p]], c); if (sz(g[i]) > 1) { chmi(lc[ind[p]], c); chma(rc[ind[p]], c); } } c++; forg(gi, g[i]) { if (t != p)q.emplace(i, t); } } fora(e, g.edges) { if (e.f < e.t) { h.add(ind[e.f], ind[e.t], e.c); } } rep(i, N) { if (l[i] == inf)l[i] = -1; if (lc[i] == inf)lc[i] = -1; } return h;} //@集計 template<class T> vi indegree(graph<T> &g) {vi ret(g.size());rep(i, g.size()) { forg(gi, g[i]) { ret[t]++; }}return ret;} template<class T> vi outdegree(graph<T> &g) {vi ret(g.size());rep(i, g.size()) { ret[i] = g[i].size(); }return ret;} #define kansetu articulation //private /*private*/ P farthest____(tree<> &E, int cur, int pre, int d, vi &D) { D[cur] = d; P r = {d, cur}; forg(gi, E[cur]) if (t != pre) { P v = farthest____(E, t, cur, d + 1, D); r = max(r, v); } return r;} //dagでなければ-1を返す int diameter(digraph<> &g) { vi per; if (!topo(per, g))return -1; int n = g.n; vi dp(n, 1); fora(v, per) { forg(gi, g[v]) { chma(dp[t], dp[f] + 1); }} return max(dp);} //iから最も離れた距離 vi diameters(tree<> &E) { /* diameter,center*/vi D[3]; D[0].resize(E.size()); D[1].resize(E.size()); auto v1 = farthest____(E, 0, 0, 0, D[0]); auto v2 = farthest____(E, v1.second, v1.second, 0, D[0]); farthest____(E, v2.second, v2.second, 0, D[1]); int i; rep(i, D[0].size()) D[2].push_back(max(D[0][i], D[1][i])); return D[2];} //iに対応するjと距離 vp diameters_p(tree<> &E) { /* diameter,center*/vector<int> D[3]; D[0].resize(E.size()); D[1].resize(E.size()); auto v1 = farthest____(E, 0, 0, 0, D[0]); auto v2 = farthest____(E, v1.second, v1.second, 0, D[0]); farthest____(E, v2.second, v2.second, 0, D[1]); int i; vp res(E.size()); rep(i, D[0].size()) { if (D[0][i] > D[1][i])res[i] = mp(v1.second, D[0][i]); else res[i] = mp(v2.second, D[1][i]); } return res;} int diameter(tree<> &E) { vi d = diameters(E); return max(d);} //最も離れた二点を返す P diameter_p(tree<> &E) { auto d = diameters_p(E); int dis = -1; int l = -1, r = -1; rep(i, sz(d)) { if (chma(dis, d[i].se)) { l = i; r = d[i].fi; } } return mp(l, r);} //@列挙 取得 //閉路がある時linfを返す template<class T> int longest_path(digraph<T> &g) { vi top; if (!topo(top, g)) { return linf; } int n = sz(top); vi dp(n, 0); for (auto &&i : top) { forg(gi, g[i]) { chma(dp[t], dp[i] + 1); }} return max(dp);} template<class T> vi longest_path_v(digraph<T> &g) { vi top; if (!topo(top, g)) { return vi(); } int n = sz(top); vi dp(n, 0); vi pre(n, -1); for (auto &&i : top) { forg(gi, g[i]) { if (chma(dp[t], dp[i] + 1)) { pre[t] = i; }}} int s = std::max_element(dp.begin(), dp.end()) - dp.begin(); vi path; while (s != -1) { path.push_back(s); s = pre[s]; } std::reverse(path.begin(), path.end()); return path;} //橋を列挙する (取り除くと連結でなくなる辺) template<class T> vp bridge(graph<T> &G) { static bool was; vp brid; vi articulation; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) brid.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) articulation.push_back(v); }; int k = 0; rep(i, G.n) { if (!vis[i]) dfs(i, -1, k); } sort(brid.begin(), brid.end()); return brid;} //間接点を列挙する (取り除くと連結でなくなる点) template<class T> vi articulation(undigraph<T> &G) { static bool was; vp bridge; vi arti; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) bridge.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) arti.push_back(v); }; int k = 0; rep(i, G.n) { if (!vis[i]) dfs(i, -1, k); } sort(arti.begin(), arti.end()); return arti;} //閉路パスを一つ返す vi close_path(digraph<> &g) { int n = g.n; vi state(n); vi path; rep(i, n) if (!state[i]) { if (fix([&](auto dfs, int v) -> bool { if (state[v]) { if (state[v] == 1) { path.erase(path.begin(), find(path.begin(), path.end(), v)); return true; } return false; } path.push_back(v); state[v] = 1; forg(gi, g[v]) { if (dfs(t))return true; } state[v] = -1; path.pop_back(); return false; })(i)) { return path; } } return vi();} vi close_path_min(digraph<> &g) { int n = g.n; vvi(dis, n); rep(i, n)dis[i] = dijkstra(g, i, linf); int mind = linf; int f = 0, t = 0; rep(i, n) { rep(j, n) { if (i == j)continue; if (chmi(mind, dis[i][j] + dis[j][i])) { f = i; t = j; } } } vi path; auto add = [&](int f, int t) { int now = f; while (now != t) { rep(i, n) { if (dis[now][i] == 1 && dis[f][i] + dis[i][t] == dis[f][t]) { path.push_back(i); now = i; break; } } } }; add(f, t); add(t, f); return path;} //iを含む最短閉路 https://atcoder.jp/contests/abc022/tasks/abc022_c /*閉路が1つしかない場合、その閉路に含まれる頂点を1としたvectorを返す*/; template<class T> vi get_close1(digraph<T> &g) { int n = g.n; queue<int> q; vi d = outdegree(g); vi res(n, 1); rep(i, n) { if (d[i] == 0) { q += i; res[i] = 0; } } auto rg = rev(g); while (q.size()) { auto now = q.front(); q.pop(); forg(gi, rg[now]) { if (--d[t] == 0) { q += t; res[t] = 0; } } } return res;} //@アルゴリズム template<class T> int krus(undigraph<T> &g) { int res = 0; unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res += e.c; }} return res;} template<class T> vector<edge_<T>> krus_ed(undigraph<T> &g) { unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); vector<edge_<T>> res; fora(e, E) { if (uf.unite(e.f, e.t)) { res.push_back(e); }} return res;} template<class T> tree<T> krus_tr(undigraph<T> &g) { tree<T> res(g.n); unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res.add(e.f, e.t); }} return res;} template<class T> int krus( vector<edge_<T>> &g) {int n=0; fora(e,g){chma(n,max(e.f,e.t)+1);}; int res = 0; unionfind uf(n); auto E = g; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res += e.c; }} return res;} template<class T> vector<edge_<T>> krus_ed( vector<edge_<T>> &g) { int n=0; fora(e,g){chma(n,max(e.f,e.t)+1);}; vector<edge_<T>> res; unionfind uf(n); auto E = g; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res += e; }} return res;}; template<class T> vi krus_i( vector<edge_<T>> &g) { int n=0; fora(e,g){chma(n,max(e.f,e.t)+1);}; vi res; unionfind uf(n); auto E = g; sort(E); int i = 0; fora(e, E) { if (uf.unite(e.f, e.t)) { res += i; } i++; } return res;} //@実験 digraph<> rang_di(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; digraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(f, t)])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(f, t)] = 1; m--; } return g;} digraph<> perfect_di(int n, bool zibun = 0) { digraph<> g(n); rep(i, n) { rep(j, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;} undigraph<> rang_un(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; undigraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(min(f, t), max(f, t))])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(min(f, t), max(f, t))] = 1; m--; } return g;} undigraph<> perfect_un(int n, bool zibun = 0){ undigraph<> g(n); rep(i, n) { rep(j, i, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;} /*頂点数がkの木を一つ返す サイズが0の木が帰ったら終了*/ tree<int> next_tree(int k) { assert(2 <= k && k < 11); static str name; static ifstream ina; static int rem; static vp edges; static int pk = -1;/*前回見たk*/ if (pk != k) { if (~pk)ina.close(); edges.clear(); pk = k; name = (k == 6) ? "C:\\Users\\kaout\\Desktop\\trees_sizek\\nazeka6.txt" : "C:\\Users\\kaout\\Desktop\\trees_sizek\\tree_size" + tos(k) + ".txt"; ina = ifstream(name); rem = pow(k, k - 2);/*Cayleyの定理*/ rep(i, k)rep(j, i + 1, k)edges.emplace_back(i, j); pk = k; } tree<int> g(k); if (rem == 0) { g.resize(0); return g; } int m; ina >> m; while (m) { int lb = lbit(m); int id = log2(lb); g.add(edges[id].first, edges[id].second); m ^= lb; } rem--; return g;} undigraph<int> next_undi(int k) { assert(2 <= k && k < 9); static str name; static ifstream ina; static int rem; static vp edges; static vi lims = {-1, -1, 1, 4, 38, 728, 26704, 1866256}; static int pk = -1;/*前回見たk*/ if (pk != k) { if (~pk)ina.close(); edges.clear(); pk = k; name = (k == 6) ? "C:\\Users\\kaout\\Desktop\\undi_sizek\\roku.txt" : "C:\\Users\\kaout\\Desktop\\undi_sizek\\undi_size" + tos(k) + ".txt"; ina = ifstream(name); rem = lims[k]; rep(i, k)rep(j, i + 1, k)edges.emplace_back(i, j); pk = k; } undigraph<int> g(k); if (rem == 0) { g.resize(0); return g; } int m; ina >> m; while (m) { int lb = lbit(m); int id = log2(lb); g.add(edges[id].first, edges[id].second); m ^= lb; } rem--; return g;} vector<tree<int>> trees(int k) { vector<tree<int>> res; while (1) { tree<int> g = next_tree(k); if (sz(g) == 0)break; res.push_back(g); } return res;} vector<undigraph<int>> undis(int k) { vector<undigraph<int>> res; while (1) { undigraph<int> g = next_undi(k); if (sz(g) == 0)break; res.push_back(g); } return res;} template<class T> vector<vector<int>> table(graph<T> &g,int init_value) { vvi(res, g.n, g.n,init_value); rep(i, g.n) { forg(gi, g[i]) { res[i][t] = c; }} return res;} //type,idが使いたい場合はgraty /*@formatter:on*/ void solve() { in(N); tree<> g(2 * k5); g.ing(N, N - 1); auto win = [&](int i) { if (i)fin("First"); else fin("Second"); }; if (N == 2) { win(0); } g.root_change_mid(); deb(g.root); mapp map; cout<<map; fix([&](auto ds, int p, int i) -> int { if (g.leaf(i)) { map[mp(p, i)] = 1; } if (map.count(mp(p, i)))return map[mp(p, i)]; int v = -1; fort(gi, g[i]) { int nv = ds(i, t); if (v == -1)v = nv ^ 1; else if (v != (nv ^ 1))v = 2; } return map[mp(p, i)] = v; deb(p, i); })(-1, g.root); deb(map); fix([&](auto ds, int p, int i) -> void { int n = sz(g[i]); int eq = 0; int t0 = g[i][0].t; int guki = map[mp(i, t0)]; int othert = t0; forg(gi, g[i]) { if (guki == map[mp(i, t)])eq++; else othert = t; } if(eq==1)othert = t0; fort(gi, g[i]) { map[mp(t, i)] = 2; } //全部ok if (eq == n) { fort(gi, g[i]) { map[mp(t, i)] = guki ^ 1; } } else if ((eq == 1 || eq == n - 1) && othert != p) { map[mp(othert, i)] = guki ^ 1; } deb(p, i); })(-1, g.root); deb(map); rep(i, N){ int cou=0; forg(gi, g[i]){ int guki = map[mp(i,t)]; if(guki == 1)cou++; } if(cou>=2){ win(1); } } win(0); } auto my(ll n, vi &a) { return 0; } auto sister(ll n, vi &a) { ll ret = 0; return ret; } signed main() { solve(); #define arg n,a #ifdef _DEBUG bool bad = 0; for (ll i = 0, ok = 1; i < k5 && ok; ++i) { ll n = rand(1, 8); vi a = ranv(n, 1, 10); auto myres = my(arg); auto res = sister(arg); ok = myres == res; if (!ok) { out(arg); cerr << "AC : " << res << endl; cerr << "MY : " << myres << endl; bad = 1; break; } } if (!bad) { // cout << "完璧 : solveを書き直そう" << endl; // cout << " : そして、solve()を呼び出すのだ" << endl; // cout << " : cin>>n; na(a,n);も忘れるな" << endl; } if (sz(message)) { cerr << "****************************" << endl; cerr << message << endl; cerr << "****************************" << endl; } #endif return 0; };
a.cc: In member function 'void tree<T>::root_change_mid()': a.cc:1785:36: error: 'message' was not declared in this scope 1785 | void root_change_mid(){ message+="N>2 (mid)\n"; assert(n>2); rep(i, n){ if(sz(g[i])>1){ root_change(i); return; } } } | ^~~~~~~
s720702064
p03726
C++
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define maxn 100010 using namespace std; int read() { int x=0,f=1; char ch=getchar(); while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();} while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; int head[maxn],nxt[maxn*2],to[maxn*2],tot; void add(int u,int v) { tot++; nxt[tot]=head[u]; head[u]=tot; to[tot]=v; } int used[maxn]; void solve(int x,int las) { for(int i=head[x];i;i=nxt[i]) { if(to[i]==las) continue; solve(to[i],x); } if(!used[x]) { if(used[las]) { puts("First"); exit(0); }#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define maxn 100010 using namespace std; int read() { int x=0,f=1; char ch=getchar(); while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();} while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();} return x*f; } int n; int head[maxn],nxt[maxn*2],to[maxn*2],tot; void add(int u,int v) { tot++; nxt[tot]=head[u]; head[u]=tot; to[tot]=v; } int used[maxn]; void solve(int x,int las) { for(int i=head[x];i;i=nxt[i]) { if(to[i]==las) continue; solve(to[i],x); } if(!used[x]) { if(used[las]) { puts("First"); exit(0); } used[x]=used[las]=1; } } int main() { n=read(); for(int i=1;i<n;i++) { int q=read(),w=read(); add(q,w); add(w,q); } used[0]=1; solve(1,0); puts("Second"); return 0; }
a.cc:39:10: error: stray '#' in program 39 | }#include<iostream> | ^ a.cc: In function 'void solve(int, int)': a.cc:39:11: error: 'include' was not declared in this scope 39 | }#include<iostream> | ^~~~~~~ a.cc:39:27: error: expected primary-expression before '>' token 39 | }#include<iostream> | ^ a.cc:45:1: error: expected primary-expression before 'using' 45 | using namespace std; | ^~~~~ a.cc:46:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 46 | int read() | ^~ a.cc:46:9: note: remove parentheses to default-initialize a variable 46 | int read() | ^~ | -- a.cc:46:9: note: or replace parentheses with braces to value-initialize a variable a.cc:47:1: error: a function-definition is not allowed here before '{' token 47 | { | ^ a.cc:57:1: error: a function-definition is not allowed here before '{' token 57 | { | ^ a.cc:65:1: error: a function-definition is not allowed here before '{' token 65 | { | ^ a.cc:81:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 81 | int main() | ^~ a.cc:81:9: note: remove parentheses to default-initialize a variable 81 | int main() | ^~ | -- a.cc:81:9: note: or replace parentheses with braces to value-initialize a variable a.cc:82:1: error: a function-definition is not allowed here before '{' token 82 | { | ^ a.cc:94:2: error: expected '}' at end of input 94 | } | ^ a.cc:34:5: note: to match this '{' 34 | { | ^ a.cc:94:2: error: expected '}' at end of input 94 | } | ^ a.cc:27:1: note: to match this '{' 27 | { | ^
s173222318
p03726
C++
nclude<bits/stdc++.h> using namespace std; const int N=1e5+5; int n,now,vi[N],fa[N],vis[N],v[N<<1],deep[N],nex[N<<1],head[N]; void addedges(int x,int y){ nex[++now]=head[x]; head[x]=now,v[now]=y; } vector<int>b[N]; void dfs(int x){ deep[x]=deep[fa[x]]+1; for(int i=head[x];i;i=nex[i]) if(v[i]!=fa[x]) fa[v[i]]=x,dfs(v[i]); b[deep[x]].push_back(x); } int main(){ scanf("%d",&n); for(int i=1;i<n;i++){ int x,y; scanf("%d%d",&x,&y); addedges(x,y),addedges(y,x); } dfs(1); for(int i=n;i;i--){ int si=b[i].size(); for(int j=0;j<si;j++){ int k=b[i][j]; if(!vis[k]){ if(vis[fa[k]]||k==1){ puts("First"); return 0; } vis[fa[k]]=1; } } } puts("Second"); return 0; }
a.cc:1:1: error: 'nclude' does not name a type 1 | nclude<bits/stdc++.h> | ^~~~~~ a.cc:9:1: error: 'vector' does not name a type 9 | vector<int>b[N]; | ^~~~~~ a.cc: In function 'void dfs(int)': a.cc:14:9: error: 'b' was not declared in this scope 14 | b[deep[x]].push_back(x); | ^ a.cc: In function 'int main()': a.cc:17:9: error: 'scanf' was not declared in this scope 17 | scanf("%d",&n); | ^~~~~ a.cc:25:24: error: 'b' was not declared in this scope 25 | int si=b[i].size(); | ^ a.cc:30:41: error: 'puts' was not declared in this scope 30 | puts("First"); | ^~~~ a.cc:37:9: error: 'puts' was not declared in this scope 37 | puts("Second"); | ^~~~
s328627414
p03726
C++
#include <bits/stdc++.h> using namespace std; #define pb push_back const int MAXN = 1e5 + 10; int n; int u ,v; int dp[MAXN]; vector <int> adj[MAXN]; vector <int> ver; void dfs(int root) { for (auto y: adj[root]) if (dp[y] == 0) dp[y] = dp[root] + 1; dfs(y); } int main() { cin >> n; if (n == 1) return cout << "First" << '\n', 0; for (int i = 1; i < n ;i++) { cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } v = 0; for (int i = 1; i <= n; i++) { if (adj[i].size() == 1) { v++; ver.pb(i); } } if (v > 2) return cout << "First" << '\n', 0; else if (v == 2) { dp[ver[0]] = 1; dfs(ver[0]); if (dp[ver[1]] % 2) return cout << "First" << '\n', 0; } cout << "Second" << '\n'; return 0; }
a.cc: In function 'void dfs(int)': a.cc:18:17: error: 'y' was not declared in this scope; did you mean 'yn'? 18 | dfs(y); | ^ | yn
s585619137
p03726
C++
#include <iostream> #include <iomanip> #include <fstream> #include <string> #include <array> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <bitset> #include <tuple> #include <cmath> #include <complex> #include <algorithm> #include <utility> #include <regex> #include <cstdint> #include <numeric> #include <functional> #include <cassert> using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll INF = 1'000'000'000'000'000'000; namespace utils{ #define ALL(x) begin(x), end(x) #define rALL(x) rbegin(x), rend(x) template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>; template<class T> using min_queue = p_queue<T, greater<T>>; template<class T> using max_queue = p_queue<T, less<T>>; template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; } template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; } using V_Set = unordered_set<int>; using E_Set = unordered_map<int, V_Set>; ll operator"" _64(unsigned long long x){ return ll(x); } ull operator"" _64u(unsigned long long x){ return ull(x); } template<class T> vector<T> make_vector(int n, T t){ return vector<T>(n, t); } template<class ...Ts> auto make_vector(int n, Ts ... ts){ return vector<decltype(make_vector(ts...))>(n, make_vector(ts...)); } template<class T> ostream& operator<<(ostream& os, const vector<T>& v){ for (auto &&x : v) { os << x << ' '; } cout << endl; return os ; } } using namespace utils; class solver{ istream& is; ostream& os; E_Set E; public: solver(istream& I, ostream& O) :is(I), os(O) {} bool dfs(int v, int p = -1){ int c = 0; for (auto &&u : E[v]) { if(u == p) continue; c += dfs(u, v); } // end if(c >= 2) throw 1; return c != 1; } bool solve(){ try{ dfs(1); return false; } catch(int k){ return true; } } void run(){ ll N; is >> N; if(!is) return; for (int i = 0; i < N - 1; ++i) { int A, B; is >> A >> B; E[A].insert(B); E[B].insert(A); } // end i cout << (solve() ? "First" : "Second") << endl; } }; int main(int argc, char *argv[]) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(16) << scientific; #ifdef DEBUG string test_cases = "test_BlackAndWhiteTree.txt"; cerr << test_cases << " -->" << endl; auto fs = fstream(test_cases, fstream::in); int loop = 0; while(fs) { loop++; cout << '#' << loop << "#------\n"; solver(fs, cout).run(); } if(loop <= 1) { cout << "===" << endl; while(cin) solver(cin, cout).run(); } #else solver(cin, cout).run(); #endif return 0; } #include <iostream> #include <iomanip> #include <fstream> #include <string> #include <array> #include <vector> #include <deque> #include <list> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <stack> #include <queue> #include <bitset> #include <tuple> #include <cmath> #include <complex> #include <algorithm> #include <utility> #include <regex> #include <cstdint> #include <numeric> #include <functional> #include <cassert> using namespace std; using ll = long long; using ull = unsigned long long; constexpr ll INF = 1'000'000'000'000'000'000; namespace utils{ #define ALL(x) begin(x), end(x) #define rALL(x) rbegin(x), rend(x) template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>; template<class T> using min_queue = p_queue<T, greater<T>>; template<class T> using max_queue = p_queue<T, less<T>>; template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; } template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; } using V_Set = unordered_set<int>; using E_Set = unordered_map<int, V_Set>; ll operator"" _64(unsigned long long x){ return ll(x); } ull operator"" _64u(unsigned long long x){ return ull(x); } template<class T> vector<T> make_vector(int n, T t){ return vector<T>(n, t); } template<class ...Ts> auto make_vector(int n, Ts ... ts){ return vector<decltype(make_vector(ts...))>(n, make_vector(ts...)); } template<class T> ostream& operator<<(ostream& os, const vector<T>& v){ for (auto &&x : v) { os << x << ' '; } cout << endl; return os ; } } using namespace utils; class solver{ istream& is; ostream& os; E_Set E; public: solver(istream& I, ostream& O) :is(I), os(O) {} bool dfs(int v, int p = -1){ int c = 0; for (auto &&u : E[v]) { if(u == p) continue; c += dfs(u, v); } // end if(c >= 2) throw 1; return c != 1; } bool solve(){ try{ dfs(1); return false; } catch(int k){ return true; } } void run(){ ll N; is >> N; if(!is) return; for (int i = 0; i < N - 1; ++i) { int A, B; is >> A >> B; E[A].insert(B); E[B].insert(A); } // end i cout << (solve() ? "First" : "Second") << endl; } }; int main(int argc, char *argv[]) { cin.tie(nullptr); ios::sync_with_stdio(false); cout << setprecision(16) << scientific; #ifdef DEBUG string test_cases = "test_BlackAndWhiteTree.txt"; cerr << test_cases << " -->" << endl; auto fs = fstream(test_cases, fstream::in); int loop = 0; while(fs) { loop++; cout << '#' << loop << "#------\n"; solver(fs, cout).run(); } if(loop <= 1) { cout << "===" << endl; while(cin) solver(cin, cout).run(); } #else solver(cin, cout).run(); #endif return 0; }
a.cc:159:14: error: redefinition of 'constexpr const ll INF' 159 | constexpr ll INF = 1'000'000'000'000'000'000; | ^~~ a.cc:31:14: note: 'constexpr const ll INF' previously defined here 31 | constexpr ll INF = 1'000'000'000'000'000'000; | ^~~ a.cc:167:28: error: redefinition of 'template<class T> bool utils::min_update(T&, const T&)' 167 | template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; } | ^~~~~~~~~~ a.cc:39:28: note: 'template<class T> bool utils::min_update(T&, const T&)' previously declared here 39 | template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; } | ^~~~~~~~~~ a.cc:168:28: error: redefinition of 'template<class T> bool utils::max_update(T&, const T&)' 168 | template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; } | ^~~~~~~~~~ a.cc:40:28: note: 'template<class T> bool utils::max_update(T&, const T&)' previously declared here 40 | template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; } | ^~~~~~~~~~ a.cc:172:8: error: redefinition of 'll utils::operator""_64(long long unsigned int)' 172 | ll operator"" _64(unsigned long long x){ return ll(x); } | ^~~~~~~~ a.cc:44:8: note: 'll utils::operator""_64(long long unsigned int)' previously defined here 44 | ll operator"" _64(unsigned long long x){ return ll(x); } | ^~~~~~~~ a.cc:173:9: error: redefinition of 'ull utils::operator""_64u(long long unsigned int)' 173 | ull operator"" _64u(unsigned long long x){ return ull(x); } | ^~~~~~~~ a.cc:45:9: note: 'ull utils::operator""_64u(long long unsigned int)' previously defined here 45 | ull operator"" _64u(unsigned long long x){ return ull(x); } | ^~~~~~~~ a.cc:176:15: error: redefinition of 'template<class T> std::vector<_Tp> utils::make_vector(int, T)' 176 | vector<T> make_vector(int n, T t){ | ^~~~~~~~~~~ a.cc:48:15: note: 'template<class T> std::vector<_Tp> utils::make_vector(int, T)' previously declared here 48 | vector<T> make_vector(int n, T t){ | ^~~~~~~~~~~ a.cc:180:10: error: redefinition of 'template<class ... Ts> auto utils::make_vector(int, Ts ...)' 180 | auto make_vector(int n, Ts ... ts){ | ^~~~~~~~~~~ a.cc:52:10: note: 'template<class ... Ts> auto utils::make_vector(int, Ts ...)' previously declared here 52 | auto make_vector(int n, Ts ... ts){ | ^~~~~~~~~~~ a.cc:185:14: error: redefinition of 'template<class T> std::ostream& utils::operator<<(std::ostream&, const std::vector<_Tp>&)' 185 | ostream& operator<<(ostream& os, const vector<T>& v){ | ^~~~~~~~ a.cc:57:14: note: 'template<class T> std::ostream& utils::operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here 57 | ostream& operator<<(ostream& os, const vector<T>& v){ | ^~~~~~~~ a.cc:191:7: error: redefinition of 'class solver' 191 | class solver{ | ^~~~~~ a.cc:63:7: note: previous definition of 'class solver' 63 | class solver{ | ^~~~~~ a.cc:234:5: error: redefinition of 'int main(int, char**)' 234 | int main(int argc, char *argv[]) { | ^~~~ a.cc:106:5: note: 'int main(int, char**)' previously defined here 106 | int main(int argc, char *argv[]) { | ^~~~
s446252183
p03726
C++
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std; const int MAXN=100000; vector<int> d[MAXN+5]; int n; int dfs(int u,int fa) { int res=0,v; for(int i=0;i<d[u].size();i++) { v=d[u][i]; if(v!=fa) res+=dfs(v,u); } if(res>=2) { printf("First\n"); exit(0); } else if(res==0) return 1; return 0; } int main() { scanf("%d",&n); for(int i=1;i<=n-1;i++) { int u,v; scanf("%d%d",&u,&v); d[u].push_back(v); d[v].push_back(u); } if(dfs(1,0)) printf("First\n"); else printf("Second\n"); return 0; }
a.cc:8:1: error: 'vector' does not name a type 8 | vector<int> d[MAXN+5]; | ^~~~~~ a.cc: In function 'int dfs(int, int)': a.cc:13:23: error: 'd' was not declared in this scope 13 | for(int i=0;i<d[u].size();i++) | ^ a.cc: In function 'int main()': a.cc:35:17: error: 'd' was not declared in this scope 35 | d[u].push_back(v); | ^
s613114644
p03726
C++
/*Lucky_Glass*/ #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=1e5; struct NODE{int pnt,tag;}nod[N+5]; vector<int> lnk[N+5]; int du[N+5],cnt[2]; bool blg[N+5]; int n; void DFS(int u,int pre){ blg[u]=!blg[pre]; for(auto v : lnk[u]){ if(v==pre) continue; DFS(v,u); } } int main(){ scanf("%d",&n); for(int i=1;i<n;i++){ int u,v;scanf("%d%d",&u,&v); lnk[u].push_back(v); lnk[v].push_back(u); du[u]++;du[v]++; } DFS(1,0); for(int u=1;u<=n;u++){ bool U=false; for(auto v : lnk[u]) if(du[v]==1){ if(U){printf("First\n");return 0;} U=true; } if(U) cnt[blg[u]]++; } for(int u=1;u<=n;u++){ if(du[u]!=1 && cnt[!blg[u]]>=lnk[u].size()){ printf("First\n"); return 0; } } printf("Second\n"); return 0; }
a.cc:11:1: error: 'vector' does not name a type 11 | vector<int> lnk[N+5]; | ^~~~~~ a.cc: In function 'void DFS(int, int)': a.cc:18:22: error: 'lnk' was not declared in this scope 18 | for(auto v : lnk[u]){ | ^~~ a.cc: In function 'int main()': a.cc:28:17: error: 'lnk' was not declared in this scope 28 | lnk[u].push_back(v); | ^~~ a.cc:35:30: error: 'lnk' was not declared in this scope 35 | for(auto v : lnk[u]) | ^~~ a.cc:43:46: error: 'lnk' was not declared in this scope 43 | if(du[u]!=1 && cnt[!blg[u]]>=lnk[u].size()){ | ^~~
s275921354
p03726
C++
/** SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ== */ #include <cstring> #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <queue> #include <cmath> #include <cstdlib> #include <ctime> #include <cassert> #define F first #define S second #define endl '\n' #define deb(x) cout<<#x<<' '<<x<<endl; #define pb push_back const long long MAXN = 1e6 + 1; using namespace std; typedef long long ll; typedef pair<int, int> pii; long long readInt() { bool minus1 = false; long long result = 0; char ch; ch = getchar(); while (true) { if (ch == '-') break; if (ch >= '0' && ch <= '9') break; ch = getchar(); } if (ch == '-') minus1 = true; else result = ch-'0'; while (true) { ch = getchar(); if (ch < '0' || ch > '9') break; result = result*10 + (ch - '0'); } if (minus1) return -result; else return result; } int kek[MAXN]; vector <int> g[MAXN]; int cnt[MAXN];- void dfs(int v, int par) { cnt[g[v].size()] ++; for (int i : g[v]) { if (g[i].size() == 1) { kek[v] ++; } if (i == par) continue; dfs(i, v); } } main() { #ifdef IZI_KATKA assert(freopen("input", "r", stdin)); assert(freopen("output", "w", stdout)); #endif int n = readInt(); for (int i = 1; i < n; i++) { int v = readInt(), u = readInt(); g[v].pb(u); g[u].pb(v); } dfs(1, 0); for (int i = 1; i <= n; i++) { if (kek[i] >= 2) { cout << "First"; return 0; } } if (cnt[1] == 2 && cnt[2] == n - 2 && n % 2) { cout << "First"; return 0; } cout << "Second"; return 0; }
a.cc:64:15: error: expected unqualified-id before '-' token 64 | int cnt[MAXN];- | ^ a.cc:77:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 77 | main() { | ^~~~ a.cc: In function 'int main()': a.cc:88:5: error: 'dfs' was not declared in this scope; did you mean 'ffs'? 88 | dfs(1, 0); | ^~~ | ffs
s061595426
p03726
C++
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; vector<int> g[maxn]; vector<int> cnt[maxn]; bool mark[maxn]; int mod = 0; int change = 0; bool is = true; void dfs(int v, int dis) { mark[v] = true; if(g[v].size() == 1) { if(dis % 2 != 0) is = false; } for(int i = 0; i < g[v].size(); i++) { if(!mark[g[v][i]]) dfs(g[v][i], dis + 1); } } bool check() { dfs(0, 0); if(is) return true; is = true; memset(mark, 0, sizeof mark); change = 0; mod = 0; dfs(g[0][0], 0); if(is) { return true; } return false; } int main() { cin >> n; for(int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } for(int i = 0; i < n; i++) { for(int j = 0; j < g[i].size(); j++) { cnt[i].push_back(g[g[i][j]].size()); } } for(int i = 0; i < n; i++){ sort(cnt[i].begin(), cnt[i].end()); } string ans = "Second"; for(int i = 0; i < n; i++){ if(cnt[i].size() >= 2) if(cnt[i][0] == 1 && cnt[i][1] == 1) { ans = "First"; return4 1 2 2 3 2 4 cout << "First", 0; } } if(check()) { ans = "First"; return cout << "First", 0; } cout << ans; return 0; }
a.cc: In function 'int main()': a.cc:62:33: error: 'return4' was not declared in this scope 62 | return4 | ^~~~~~~
s439545712
p03726
C++
#include<bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; int n; vector<int> g[maxn]; vector<int> cnt[maxn]; bool mark[maxn]; int mod = 0; int change = 0; void dfs(int v, int dis) { mark[v] = true; if((int)g[v].size() == 1) { if(dis % 2 != mod) { change++; mod = dis % 2; } } for(int i = 0; i < g[v].size(); i++) { if(!mark[g[v][i]]) { dfs(g[v][i], dis + 1); } } } bool check() { dfs(0, 0); if(mod == 0 && change <= 1) { return true; } memset(mark, 0, sizeof mark); change = 0; mod = 0; dfs(g[0][0], 0); if(mod == 0 && change <= 1) { return true; } return false; } int main() { cin >> n; for(int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--, v--; g[u].push_back(v); g[v].push_back(u); } for(int i = 0; i < n; i++) { for(int j = 0; j < g[i].size(); j++) { cnt[i].push_back(g[g[i][j]].size()); } } for(int i = 0; i < n; i++){ sort(cnt[i].begin(), cnt[i].end()); } return cout << "First", 0; string ans = "Second"; for(int i = 0; i < n; i++){ if(cnt[i].size() >= 2) if(cnt[i][0] == 1 && cnt[i][1] == 1) { ans = "First"; return cout << "First", 0; } } if(check()) { ans = "First"; return cout << "First", 0; } if() cout << ans; return 0; }
a.cc: In function 'int main()': a.cc:72:12: error: expected primary-expression before ')' token 72 | if() | ^
s939376405
p03726
C++
#include <iostream> #include <vector> using namespace std; const int MAXn = 1e5 + 10; vector<int> g[MAXn]; int n, odd[MAXn], even[MAXn]; void dfs(int v, int par) { if (g[v].size() == 1 && par != 0) even[v] = 1; for (int i = 0; i < g[v].size(); i++) if (g[v][i] != par) { dfs(g[v][i], v); odd[v] += (even[g[v][i]]); even[v] += (odd[g[v][i]]); } } void dfs2(int v, int par) { if (!par) even[v]++; for (int i = 0; i < g[v].size(); i++) if (g[v][i] != par) { if (even[v] - (odd[g[v][i]]) > 0) { odd[g[v][i]]+= even[v] - (odd[g[v][i]]); } if (odd[v] - (even[g[v][i]]) > 0) even[g[v][i]]+= odd[v] - (even[g[v][i]]); dfs2(g[v][i], v); } } int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int u, v; cin >> u>> v; g[u].push_back(v); g[v].push_back(u); } dfs(1, 0); dfs2(1, 0); for (int i = 1; i<= n; i++) leaf += g[i].size() == 1; for (int i = 1; i <= n; i++) { int cnt = 0; for (int j = 0; j < g[i].size(); j++) if (g[g[i][j]].size() == 1) cnt++; if (cnt > 1) return cout << "First",0; } for (int i = 1; i <= n; i++) { //cout << i <<' ' << g[i].size() << ' ' << even[i] << ' ' << odd[i] << endl; if ((!even[i] || !even[i]) && g[i].size() > 1) return cout << "First",0; } cout << "Second"; }
a.cc: In function 'int main()': a.cc:44:17: error: 'leaf' was not declared in this scope 44 | leaf += g[i].size() == 1; | ^~~~
s940514037
p03726
C++
#include <iostream> #include <vector> #include <utility> #include <string> #include <map> #include <algorithm> #define rep(i,n) for(int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; vector<int>g[100000]; int dp[100000][2]; void dfs(int s, int p){ int ma = -1000000; for(int x:g[s]){ if(x == p)continue; dfs(x,s); dp[s][0] += dp[x][1]; ma = max(dp[x][0] - dp[x][1]); } dp[s][1] = dp[s][0] + 1 + ma; } int main(){ int n; cin >> n; rep(i,n-1){ int a,b; cin >> a >> b; a--,b--; g[a].push_back(b); g[b].push_back(a); } dfs(0,-1); if(n%2==0 and dp[0][1] == n/2){ cout << "Second" << endl; }else{ cout << "First" << endl; } }
a.cc: In function 'void dfs(int, int)': a.cc:18:17: error: no matching function for call to 'max(int)' 18 | ma = max(dp[x][0] - dp[x][1]); | ~~~^~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 1 provided In file included from /usr/include/c++/14/algorithm:61, from a.cc:6: /usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)' 5706 | max(initializer_list<_Tp> __l) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5706:5: note: template argument deduction/substitution failed: a.cc:18:17: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 18 | ma = max(dp[x][0] - dp[x][1]); | ~~~^~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)' 5716 | max(initializer_list<_Tp> __l, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate expects 2 arguments, 1 provided
s764104741
p03726
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; vector<int> pathes[100200]; int dist[100200]; bool flag = false; vector<int> connect; bool allOdds[100200]; void search(int from, int now, int cost){ if(dist[now] == INF){ dist[now] = cost; if(pathes[now].size() > 2){ connect.push_back(now); if(cost % 2 == 0){ allOdds[now] = false; } return; } for(int i = 0; i < pathes[now].size(); i++){ if(pathes[now][i] == from) continue; search(now, pathes[now][i], cost + 1); } return; } if(dist[now] % 2 == 0){ if(cost % 2 == 0){ flag = true; return; } return; } if(cost % 2 == 0){ allodds[now] = false; } dist[now] = cost; return; } int main() { //cout.precision(10); int n; cin >> n; for(int i = 1; i < n; i++){ int a, b; cin >> a >> b; pathes[a].push_back(b); pathes[b].push_back(a); } int first = 0; bool leaf[100200]; for(int i = 1; i <= n; i++){ allOdds[i] = true; if(pathes[i].size() == 1){ leaf[i] = true; if(first == 0){ first = i; } } else { leaf[i] = false; } } for(int i = 1; i <= n; i++){ dist[i] = INF; } /*for(int i = 1; i <= n; i++){ int counter = 0; for(int j = 0; j < pathes[i].size(); j++){ if(leaf[pathes[i][j]]){ counter++; } } if(counter >= 2){ cout << "First" << endl; return 0; } }*/ for(int i = 1; i <= n; i++){ if(leaf[i]){ if(dist[i] != INF){ if(dist[i] % 2 == 1){ cout << "First" << endl; return 0; } } search(1000000, i, 1); if(flag){ cout << "First" << endl; return 0; } } } for(int i = 0; i < connect.size(); i++){ if(allOdds[i]){ cout << "First" << endl; return 0; } } cout << "Second" << endl; return 0; }
a.cc: In function 'void search(int, int, int)': a.cc:39:9: error: 'allodds' was not declared in this scope; did you mean 'allOdds'? 39 | allodds[now] = false; | ^~~~~~~ | allOdds
s475513105
p03726
C++
#include<iostream> #include<cstring> #include<algorithm> #include<cstdio> #include<cmath> #include<cassert> #define ll long long using namespace std; inline int read(){ int re=0,flag=1;char ch=getchar(); while(ch>'9'||ch<'0'){ if(ch=='-') flag=-1; ch=getchar(); } while(ch>='0'&&ch<='9') re=(re<<1)+(re<<3)+ch-'0',ch=getchar(); return re*flag; } int n,first[100010],dep[100010],cnte=-1,cur[100010]; struct edge{ int to,next,w; }a[600010]; inline void add(int u,int v,int w){ a[++cnte]=(edge){v,first[u],w};first[u]=cnte; a[++cnte]=(edge){u,first[v],w};first[v]=cnte; } vector<int>e[100010]; void getd(int u,int f){ int i,v;dep[u]=dep[f]+1; if(dep[u]&1){ add(0,u,1); if(f) add(u,f,1); } else{ add(u,n+1,1); if(f) add(f,u,1); } for(i=0;i<e[u].size();i++) if((v=e[u][i])!=f) getd(v,u); } int q[100010],head,tail; bool bfs(int s,int t){ int i,u,v;head=0,tail=1; for(i=s;i<=t;i++) dep[i]=-1,cur[i]=first[i]; dep[s]=0;q[0]=s; while(head<tail){ u=q[head++]; for(i=first[u];~i;i=a[i].next){ v=a[i].to;if(~dep[v]||!a[i].w) continue; dep[v]=dep[u]+1;q[tail++]=v; } } return ~dep[t]; } int dfs(int u,int t,int lim){ if(u==t||!lim) return lim; int i,v,f,flow=0; for(i=cur[u];~i;i=a[i].next){ v=a[i].to;cur[u]=i; if(dep[v]==dep[u]+1&&(f=dfs(v,t,min(lim,a[i].w)))){ flow+=f;lim-=f; a[i].w-=f;a[i^1].w+=f; if(!lim) return flow; } } return flow; } int dinic(int s,int t){ int re=0; while(bfs(s,t)) re+=dfs(s,t,1e9); return re; } int main(){ memset(first,-1,sizeof(first)); n=read();int i,t1,t2; for(i=1;i<n;i++){ t1=read();t2=read(); e[t1].push_back(t2); e[t2].push_back(t1); } getd(1,0); if(dinic(0,n+1)*2==n) puts("Second"); else puts("First"); }
a.cc:26:1: error: 'vector' does not name a type 26 | vector<int>e[100010]; | ^~~~~~ a.cc: In function 'void getd(int, int)': a.cc:37:19: error: 'e' was not declared in this scope 37 | for(i=0;i<e[u].size();i++) if((v=e[u][i])!=f) getd(v,u); | ^ a.cc: In function 'int main()': a.cc:76:17: error: 'e' was not declared in this scope 76 | e[t1].push_back(t2); | ^
s677364746
p03726
C++
#include "bits/stdc++.h" #define ll long long #define rep2(i,a,b) for(int i=a;i<=b;++i) #define rep(i,n) for(int i=0;i<n;i++) #define pii pair<int,int> #define tii tuple<int,int,int> #define pq priority_queue<int> #define pqg priority_queue<int,vector<int>,greater<int>> #define pb push_back #define edge(v,a,b) v[a].pb(b);v[b].pb(a); ll int MOD=1e9+7; #define INF 2*1e9 #define N 310000 using namespace std; string alphabet("abcdefghijklmnopqrstuvwxyz"); vector<int> v[N]; int used[N]; int dfs(int a){ int t=0; int ans=1; Used[a]=1; rep(i,v[a].size()){ int b=v[a][i]; if(v[b].size()==1) t++; if(!used[b]) ans=ans&dfs(); } if(t>1) ans=0; return ans; } main(){ int n; cin>>n; rep(i,n-1){ int a,b; cin>>a>>b; v[a].pb(b); v[b].pb(a); } int mem[N]={}; rep2(i,1,n){ int t=0; rep(j,v[i].size()){ if(v[v[i][j]].size()==1){ t++; } } if(t>1){ cout<<"First";return 0; } if(t) mem[i]=1; } rep2(i,1,n){ bool flag=true; rep(j,v[i].size()){ if(!mem[v[i][j]]) flag=false; } if(flag){ cout<<"First"; return 0; } } cout<<"Second";return 0; }
a.cc: In function 'int dfs(int)': a.cc:21:5: error: 'Used' was not declared in this scope; did you mean 'used'? 21 | Used[a]=1; | ^~~~ | used a.cc:25:33: error: too few arguments to function 'int dfs(int)' 25 | if(!used[b]) ans=ans&dfs(); | ~~~^~ a.cc:18:5: note: declared here 18 | int dfs(int a){ | ^~~ a.cc: At global scope: a.cc:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 30 | main(){ | ^~~~
s503667322
p03726
C++
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<queue> #include<deque> #include<map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; i++ ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; const int inf=1e9+7; const ll longinf=1LL<<60; const ll mod=1e9+7; int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1}; vector<int> v[101010]; int n,dp[2][101010]; int dfs(int k,int x,int par){ if(dp[x][k]!=0)return dp[x][k]; int ret=0; if(x==1){ ret=1; for(auto e:v[k])if(e!=par)ret+=min(dfs(e,1,k),dfs(e,0,k)); } else for(auto e:v[k])if(e!=par)ret+=dfs(e,1,k); return dp[x][k]=ret; } int main(){ cin>>n; rep(i,n-1){ int a,b; cin>>a>>b; a--; b--; v[a].push_back(b); v[b].push_back(a); } a[0]=1; int ans=min(dfs(0,1,-1),dfs(0,0,-1)); if(2*ans<n)cout<<"First"<<endl; else cout<<"Second"<<endl; return 0; }
a.cc: In function 'int main()': a.cc:44:5: error: 'a' was not declared in this scope 44 | a[0]=1; | ^
s525364493
p03726
C++
#include<bits/stdc++.h> #define N 200005 using namespace std; int head[N],ver[N],nxt[N],tot; void add(int a,int b) { tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ; } int g[N]; bool flag,n; void dfs(int x,int f) { g[x]=0; for(int i=head[x];i;i=nxt[i]) { if(ver[i]==f)continue; dfs(ver[i],x); if(!g[ver[i]]) { if(!g[x])g[x]=1; else flag=1; } } } int main() { scanf("%d",&n) tot=0; int t1,t2;flag=0; for(int i=1;i<n;i++) { scanf("%d%d",&t1,&t2); add(t1,t2);add(t2,t1); } dfs(1,-1); for(int i=1;i<=n;i++)head[i]=0; if(flag||!g[1])puts("First"); else puts("Second"); return 0; }
a.cc: In function 'int main()': a.cc:27:23: error: expected ';' before 'tot' 27 | scanf("%d",&n) | ^ | ; 28 | 29 | tot=0; | ~~~
s455476833
p03726
C++
#include<iostream> #include<vector> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #include<cstdlib> #include<ctime> #include<queue> #include<set> using namespace std; typedef long long LL; const int N=2e5; int gi() { int w=0;bool q=1;char c=getchar(); while ((c<'0'||c>'9') && c!='-') c=getchar(); if (c=='-') q=0,c=getchar(); while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar(); return q? w:-w; } int head[N],next[N],to[N]; inline bool dfs(int k,int fa) { bool match=false; for (int i=head[k];i;i=next[i]) if (to[i]!=fa) { if (dfs(to[i],k)) if (match) { puts("First"); exit(0); } else match=true; } return !match; } int main() { int n=gi(),i,a,b,tot=0; for (i=1;i<n;i++) { a=gi(),b=gi(); to[++tot]=b,next[tot]=head[a],head[a]=tot; to[++tot]=a,next[tot]=head[b],head[b]=tot; } puts(dfs(1,0)?"First":"Second"); return 0; }
a.cc: In function 'bool dfs(int, int)': a.cc:24:32: error: reference to 'next' is ambiguous 24 | for (int i=head[k];i;i=next[i]) | ^~~~ In file included from /usr/include/c++/14/string:47, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:21:13: note: 'int next [200000]' 21 | int head[N],next[N],to[N]; | ^~~~ a.cc: In function 'int main()': a.cc:37:29: error: reference to 'next' is ambiguous 37 | to[++tot]=b,next[tot]=head[a],head[a]=tot; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:21:13: note: 'int next [200000]' 21 | int head[N],next[N],to[N]; | ^~~~ a.cc:38:29: error: reference to 'next' is ambiguous 38 | to[++tot]=a,next[tot]=head[b],head[b]=tot; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)' 232 | next(_InputIterator __x, typename | ^~~~ a.cc:21:13: note: 'int next [200000]' 21 | int head[N],next[N],to[N]; | ^~~~
s465916606
p03726
C++
#include<cstdio> #include<vector> #include<bitset> #define N 100000 using namespace std; vector<int> vecin[N+1]; bitset<N+1> viz; int dfs(int nod){ viz.set(nod); bool ans=false; for(int i=0;i<vecin[nod].size();i++){ int now=vecin[nod][i]; if (viz[now]==false){ int r=dfs(now); if (r==-1) return -1; if (r==1 &&ans==1) return -1; ans|=r; } } return (ans^1); } int main(){ int n,i; scanf ("%d",&n); for(i=1;i<=n;i++){ int a,b; scanf ("%d%d",&a,&b); vecin[a].push_back(b); vecin[b].push_back(a); } int ans=dfs(); if (ans==0) printf ("Second"); else printf ("First"); return 0; }
a.cc: In function 'int main()': a.cc:42:16: error: too few arguments to function 'int dfs(int)' 42 | int ans=dfs(); | ~~~^~ a.cc:10:5: note: declared here 10 | int dfs(int nod){ | ^~~
s859160226
p03726
C++
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 1000000007LL #define rep(i, n) for(int i = 0; i < (n); i++) #define rrep(i, n) for(int i = (n) - 1; i >= 0; i--) #define trep(i, n) for(int i = 0; i <= (n); i++) #define rep1(i, n) for(int i = 1; i <= (n); i++) #define mfor(i, s, t) for(int i = (s); i < (t); i++) #define tfor(i, s, t) for(int i = (s); i <= (t); i++) class Dinic { public: vector<vector<pair<int, int>>> v; vector<int> e; vector<int> k; vector<int> j; void init(int n) { v = vector<vector<pair<int, int>>>(n); e = vector<int>(); k = vector<int>(n); j = vector<int>(n); } void add_edge(int a, int b, int atob, int btoa = 0) { v[a].push_back(make_pair(b, e.size())); e.push_back(atob); v[b].push_back(make_pair(a, e.size())); e.push_back(btoa); } void dyk(int s) { for(auto& i : k) { i = inf; } queue<pair<int, int>> pq; pq.push(make_pair(0, s)); while(!pq.empty()) { int w = pq.front().first; int b = pq.front().second; pq.pop(); if(k[b] > w) { k[b] = w; for(auto i : v[b]) { if(e[i.second] > 0) { pq.push(make_pair(w + 1, i.first)); } } } } } int dfs(int s, int t, int p, int c) { if(p == t) { return c; } int all = 0; while(c > all && j[p] < v[p].size()) { if(k[v[p][j[p]].first] == k[p] + 1) { int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second])); e[v[p][j[p]].second] -= r; e[v[p][j[p]].second ^ 1] += r; if(r < c - all) { j[p]++; } all += r; } else { j[p]++; } } return all; } int solve(int s, int t) { int all = 0; while(1) { dyk(s); for(auto& i : j) { i = 0; } int r = dfs(s, t, s, inf); if(r == 0) { return all; } all += r; } } }; class Rmq { public: vector<int> d; int n; void init(int nw) { n = 1; while(n < nw) { n *= 2; } d.resize(n * 2); rep(i, n * 2) { d[i] = inf * inf; } } void set_(int b, int x, int p, int nb, int ne) { if(nb <= b && b < ne) { if(nb == ne - 1) { d[p] = min(d[p], x); } else { int m = (nb + ne) / 2; set_(b, x, p * 2 + 1, nb, m); set_(b, x, p * 2 + 2, m, ne); d[p] = min(d[p * 2 + 1], d[p * 2 + 2]); } } } void set(int b, int x) { set_(b, x, 0, 0, n); } int get_(int b, int e, int p, int nb, int ne) { if(b <= nb && ne <= e) { return d[p]; } else if(ne <= b || e <= nb) { return inf * inf; } else { int m = (nb + ne) / 2; return min(get_(b, e, p * 2 + 1, nb, m), get_(b, e, p * 2 + 2, m, ne)); } } int get(int b, int e) { return get_(b, e, 0, 0, n); } }; vector<int> v[114514]; pair<pair<bool, bool>, pair<bool, bool>> dfs(int p, int o) { if(v[p].size() == 1) { return make_pair(make_pair(true, false), make_pair(false, false)); } pair<pair<bool, bool>, pair<bool, bool>> r = make_pair(make_pair(false, false), make_pair(false, false)); int k = 0; for(auto i : v[p]) { if(i != o) { auto w = dfs(i, p); if(w.first.first) { k++; r.first.second = true; } if(w.first.second) { r.first.first = true; } if(w.second.first) { r.second.second = true; } if(w.second.second) { r.second.first = true; } } } if(k >= 2 || (w.first.first && w.second.first) || (w.first.second && w.second.second)) { cout << "First" << endl; exit(0); } if(k == 1) { r.second.second = true; } return r; } signed main() { int n; cin >> n; rep(i, n - 1) { int a, b; cin >> a >> b; v[a - 1].push_back(b - 1); v[b - 1].push_back(a - 1); } dfs(0, -1); cout << "Second" << endl; }
a.cc: In function 'std::pair<std::pair<bool, bool>, std::pair<bool, bool> > dfs(long long int, long long int)': a.cc:165:17: error: 'w' was not declared in this scope 165 | if(k >= 2 || (w.first.first && w.second.first) || (w.first.second && w.second.second)) { | ^
s422951957
p03726
C++
#include <bits/stdc++.h> using namespace std; vector<int> e[1000500]; int p[1000500] int n; void link(int a,int b) { e[a].push_back(b); e[b].push_back(a); } void dfs(int u,int fa) { for (int i=0;i<e[u].size();i++) { int v=e[u][i]; if (v==fa) continue; dfs(v,u); } if (!p[u] && !p[f]) p[u] = p[f] = 1; } int main() { cin>>n; for (int i=1;i<n;i++) { int x,y; cin>>x>>y; link(x,y); } p[0] = 1; dfs(1,0); int ans = 1; for (int i=1;i<=n;i++) if (!p[i]) ans = 0; puts(!ans?"First":"Second"); return 0; }
a.cc:5:1: error: expected initializer before 'int' 5 | int n; | ^~~ a.cc: In function 'void dfs(int, int)': a.cc:20:10: error: 'p' was not declared in this scope 20 | if (!p[u] && !p[f]) p[u] = p[f] = 1; | ^ a.cc:20:21: error: 'f' was not declared in this scope 20 | if (!p[u] && !p[f]) p[u] = p[f] = 1; | ^ a.cc: In function 'int main()': a.cc:24:10: error: 'n' was not declared in this scope; did you mean 'yn'? 24 | cin>>n; | ^ | yn a.cc:31:5: error: 'p' was not declared in this scope 31 | p[0] = 1; | ^
s068232765
p03726
C++
// g++ temp.cpp // C++ includes used for precompiling -*- C++ -*- // Copyright (C) 2003-2013 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the // terms of the GNU General Public License as published by the // Free Software Foundation; either version 3, or (at your option) // any later version. // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // Under Section 7 of GPL version 3, you are granted additional // permissions described in the GCC Runtime Library Exception, version // 3.1, as published by the Free Software Foundation. // You should have received a copy of the GNU General Public License and // a copy of the GCC Runtime Library Exception along with this program; // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // <http://www.gnu.org/licenses/>. /** @file stdc++.h * This is an implementation file for a precompiled header. */ // 17.4.1.2 Headers // C //#ifndef _GLIBCXX_NO_ASSERT #include <cassert> #include <cctype> #include <cerrno> #include <cfloat> #include <ciso646> #include <climits> #include <clocale> #include <cmath> #include <csetjmp> #include <csignal> #include <cstdarg> #include <cstddef> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> /* //#if __cplusplus >= 201103L #include <ccomplex> #include <cfenv> #include <cinttypes> #include <cstdbool> #include <cstdint> #include <ctgmath> #include <cwchar> #include <cwctype> */ // C++ #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> /* //#if __cplusplus >= 201103L #include <array> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <typeindex> #include <type_traits> #include <unordered_map> #include <unordered_set> */ using namespace std; #define fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define maxch(x,y) x=max(x,y) #define minch(x,y) x=min(x,y) #define mp(a,b) make_pair(a,b) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #define maxch(x,y) x=max(x,y) #define minch(x,y) x=min(x,y) #define uni(x) x.erase(unique(all(x)),x.end()) template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;} template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;} #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MIN(a, b) ((a) > (b) ? (b) : (a)) typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<P, int> PPI; #define INF INT_MAX/3 #define MAX_N 1000 int n; vector<int> g[111111]; P dfs(int v,int pre){ if(g[v].size()==1&&g[v][0]==pre){ //他につながっている頂点が先につながっていると評価されたもの以外無ければsecondがfalseであると返す return P(true,false); } int cnt = 0; for(int nv:g[v]){ //ループ防止の為 if(nv!=pre){ P tmp = dfs(nv,v); if(!tmp.fi) return P(false,false); if(!tmp.se) cnt++; } } return P(cnt <=1,cnt == 1); } void solve(){ cin.tie(0); ios::sync_with_stdio(false); cin>>n; rep(i,n-1){ int a,b; cin>>a>>b; a--; b--; g[a].pb(b); g[b].pb(a); } P res=dfs(0,-1): if(res.fi&&res.se) cout<<"Second"<<endl; else cout<<"First"<<endl; } int main(){ solve(); return 0; }
a.cc: In function 'void solve()': a.cc:176:18: error: expected ',' or ';' before ':' token 176 | P res=dfs(0,-1): | ^ a.cc:178:3: error: 'else' without a previous 'if' 178 | else cout<<"First"<<endl; | ^~~~
s435613663
p03726
C++
#include <iostream> #include <vector> #include <algorithm> #include <cstdio> using namespace std; const int M = 1e5 + 10; vector<int>vc[M]; int ans , V[M]; void dfs(int pos , int pre , int d) { int len = vc[pos].size(); if(d >= 4) { V[pos]++; } if(len > 2) { return ; } else { for(int i = 0 ; i < len ; i++) { int v = vc[pos][i]; if(v != pre) { dfs(v , pos , d + 1); } } } } int main() { int n , u , v; scanf("%d" , &n); for(int i = 1 ; i < n ; i++) { scanf("%d%d" , &u , &v); vc[u].push_back(v); vc[v].push_back(u); } memset(V , 0 , sizeof(V)); int flag = 1; for(int i = 1 ; i <= n ; i++) { int len = vc[i].size(); int count = 0; if(len >= 2) { for(int j = 0 ; j < len ; j++) { int to = vc[i][j]; int len = vc[to].size(); if(len == 1) { count++; } } if(count >= 2) { flag = 0; break; } } } if(!flag) { printf("First\n"); } else { ans = 0; for(int i = 1 ; i <= n ; i++) { int len = vc[i].size(); if(len == 1) { dfs(i , -1 , 1); } } for(int i = 1 ; i <= n ; i++) { int len = vc[i].size(); if(len >= 2) { for(int j = 0 ; j < len ; j++) { int to = vc[i][j]; int len = vc[to].size(); if(len == 1) { if(V[i] >= 1) { ans = 1; break; } } else { if(V[i] >= 2) { ans = 1; break; } } } } if(ans) break; } if(ans) { printf("First\n"); } else { printf("Second\n"); } } return 0; }
a.cc: In function 'int main()': a.cc:34:5: error: 'memset' was not declared in this scope 34 | memset(V , 0 , sizeof(V)); | ^~~~~~ a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 4 | #include <cstdio> +++ |+#include <cstring> 5 | using namespace std;
s370450262
p03726
C++
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<map> #include<set> #include<deque> using namespace std; #define sz(x) (int)(x.size()) #define rep(i, a, b) for(int i=a;i<b;++i) #define per(i, a, b) for(int i=b-1;i>=a;--i) #define pb push_back #define mp make_pair typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; //////////////// string const F = "First"; string const S = "Second"; int const N = 1e5 + 41; vector<int> e[N]; int root; int l[N]; int n; int cnt[N]; int par[N]; int w[N]; deque<int> q; void print(string ans){ cout << ans << endl; exit(0); } int dfs(int u, int p){ if(sz(e[u]) == 1) l[u] = 1; par[u] = p; int cnt = 0; rep(i, 0, sz(e[u])){ int to = e[u][i]; if(to == p) continue; cnt += dfs(to, u); } if(cnt > 1) print(F); return l[u]; } void solve(){ cin >> n; rep(i, 0, n-1){ int a, b; cin >> a >> b; --a;--b; e[a].pb(b); e[b].pb(a); } rep(i, 0, n) if(sz(e[i]) > sz(e[root])) root = i; ++cnt[root]; dfs(root, -1); rep(i, 0, n){ cnt[i] = sz(e[i]); if(l[i]) q.pb(i); } while(sz(q)){ int v = q.front(); q.pop_front(); if(par[v] == -1){ continue; } if(!w[v] && w[par[v]]) print(F); --cnt[par[v]]; if(cnt[par[v]] == 1) q.pb(par[v]); if(!w[v]){ w[par[v]] = 1; w[v] = 1; } } rep(i, 0, n) if(!w[v]) print(F); print(S); } int main(){ #ifdef _DEBUG freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); return 0; }
a.cc: In function 'void solve()': a.cc:86:28: error: 'v' was not declared in this scope 86 | rep(i, 0, n) if(!w[v]) print(F); | ^
s659295543
p03726
C++
#include <iostream> #include <vector> #include <queue> using namespace std; int n; vector<int> et[100000]; int dist[100001]; int cnt[200001]; int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; et[a].push_back(b); et[b].push_back(a); } queue<int> que; for (int i = 0; i < n; i++) { dist[i] = 11451419; if (et[i].size() == 1) { dist[i] = 0; que.push(i); } } while (!que.empty()) { int v = que.front(); que.pop(); for (int i = 0; i < et[v].size(); i++) { if (dist[et[v][i]] > dist[v] + 1) { dist[et[v][i]] = dist[v] + 1; que.push(et[v][i]); } } } for (int i = 0; i < n; i++) { cnt[dist[i]]++; } int rem = n; for (int i = 0; ; i += 2) { if (rem == 0 || rem == 2) { break; } if (cnt[i] > cnt[i + 1]) { //葉の個数 > 葉の親の個数 assert(0); cout << "First" << endl; return 0; } rem -= cnt[i]; rem -= cnt[i + 1]; } cout << "Second" << endl; return 0; }
a.cc: In function 'int main()': a.cc:48:25: error: 'assert' was not declared in this scope 48 | assert(0); | ^~~~~~ a.cc:4:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>' 3 | #include <queue> +++ |+#include <cassert> 4 | using namespace std;
s169937579
p03726
C++
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); int N; cin >> N; auto adjacency_list = vector<vector<int>>(N); for (auto i = 0; i < N-1; i++) { int a, b; cin >> a >> b; a--; b--; adjacency_list[a].push_back(b); adjacency_list[b].push_back(a); } auto matched = vector<bool>(N); const function<void(int, int)> dfs = [&](const int v, const int parent) { for (const auto child : adjacency_list[v]) if (child != parent) { dfs(child, v); if (!matched[child] && !matched[v]) matched[child] = matched[v] = true; } }; dfs(0, -1); cout << (all_of(begin(matched), end(matched)) ? "Second" : "First") << endl; }
a.cc: In function 'int main()': a.cc:31:20: error: no matching function for call to 'all_of(std::vector<bool>::iterator, std::vector<bool>::iterator)' 31 | cout << (all_of(begin(matched), end(matched)) ? "Second" : "First") << endl; | ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:1: /usr/include/c++/14/bits/stl_algo.h:410:5: note: candidate: 'template<class _IIter, class _Predicate> bool std::all_of(_IIter, _IIter, _Predicate)' 410 | all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) | ^~~~~~ /usr/include/c++/14/bits/stl_algo.h:410:5: note: candidate expects 3 arguments, 2 provided In file included from /usr/include/c++/14/algorithm:86: /usr/include/c++/14/pstl/glue_algorithm_defs.h:30:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Predicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, bool> std::all_of(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, _Predicate)' 30 | all_of(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, _Predicate __pred); | ^~~~~~ /usr/include/c++/14/pstl/glue_algorithm_defs.h:30:1: note: candidate expects 4 arguments, 2 provided
s489283550
p03726
C++
#include <iostream> #include <vector> #include <queue> #include <unordered_map> #include <map> #include <string> #include <iomanip> #include <cmath> #include <cstring> #include <algorithm> #define MaxN 100005 using namespace std; int N,X,Y; bool pos=false; vector<int>Graph[MaxN]; int DFS(int node,int father) { int cnt=0; for(int i=0;i<Graph[node].size();i++) { if(Graph[node][i]==father) continue; cnt+=DFS(Graph[node][i],node); } if(cnt>=2||) pos=true; return !cnt; } int main() { cin>>N; for(int i=1;i<N;i++) { cin>>X>>Y; Graph[X].push_back(Y); Graph[Y].push_back(X); } int i=1; while(i<N&&Graph[i].size()==1) i++; DFS(i,0); if(pos) cout<<"First\n"; else cout<<"Second\n"; return 0; }
a.cc: In function 'int DFS(int, int)': a.cc:28:20: error: expected primary-expression before ')' token 28 | if(cnt>=2||) | ^
s042121051
p03726
C++
#include<algorithm> #include<vector> #include<list> #include<iostream> #include<utility> #include<string> #include<set> #include<queue> #include<stack> #include<iterator> #include<map> #include<limits> #include<iomanip> #include<ctime> #include<cmath> const int INF=2147483647; const long long MOD=1e9+7; using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; vector<vector<int>> graph(n+1); for(int i=1; i<=n-1; i++){ int x,y; cin>>x>>y; graph[x].push_back(y); graph[y].push_back(x); } vector<int> leaves; vector<int> preds(n+1); set<int> leafPreds; for(int i=1; i<=n; i++){ if(graph[i].size()==1){ leaves.push_back(i); preds[i]=graph[i][0]; } } for(int i:leaves){ //cout<<i<<endl; if(leafPreds.find(preds[i])!=leafPreds.end()){ cout<<"First"; return 0; } else{ leafPreds.insert(preds[i]); } } for(int i:leaves){ pathCt=2; int j=preds[i]; if(graph[j].size==2){ pathCt++; int k=graph[j][0]==i?graph[j][1]:graph[j][0]; if(graph[k].size==2){ cout<<"First"; return 0; } } } cout<<"Second"; return 0; }
a.cc: In function 'int main()': a.cc:64:9: error: 'pathCt' was not declared in this scope 64 | pathCt=2; | ^~~~~~ a.cc:66:21: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?) 66 | if(graph[j].size==2){ | () a.cc:69:25: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' (did you forget the '()' ?) 69 | if(graph[k].size==2){ | ()
s675020644
p03726
C++
#include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<vector> #include<algorithm> using namespace std; vector<int> E[100010]; int d[100010], cnt[100010], ans[100000]; int vis[100010], flag[100010], ok; int n, u, v, t, cot, tot; void dfs(int x){ for(int i = 0; i < E[x].size(); i++){ if(!vis[E[x][i]]){ vis[E[x][i]] = 1; d[E[x][i]] = d[x] + 1; dfs(E[x][i]); } } } int main() { scanf("%d", &n); for(int i = 1; i <= n - 1; i++){ scanf("%d%d", &u, &v); E[u].push_back(v); E[v].push_back(u); cnt[v]++; cnt[u]++; } dfs(1); for(int i = 1; i <= n; i++)if(cnt[i] == 1)ans[++t] = i; if(t >= 3){ for(int i = 1; i <= t; i++) for(int j = 1; j <= t; j++) if(sqrt(d[i] - d[j]) >= 4)flag++; if(flag >= 2)printf("Second\n"); else printf("First\n"); } else { printf("First\n"); } }
a.cc: In function 'int main()': a.cc:36:59: error: lvalue required as increment operand 36 | if(sqrt(d[i] - d[j]) >= 4)flag++; | ^~~~ a.cc:37:25: error: ISO C++ forbids comparison between pointer and integer [-fpermissive] 37 | if(flag >= 2)printf("Second\n"); | ~~~~~^~~~
s684849600
p03726
C++
#include <bits/stdc++.h> using namespace std; #define mps 1000000007 vector <int> vec[100005]; bool ok(int x) { for(int i=0;i<vec[x].size();i++) { if(vec[vec[x][i]].size()==1) return 1; } return 0; } int main() { bool flag=0; int n,u,v; cin>>n; for(int i=1;i<n;i++) { scanf("%d%d",&u,&v); vec[u].push_back(v); vec[v].push_back(u); } for(int i=1;i<=n;i++) { if(vec[i].size()>1) { int cnt=0; for(int j=0;j<vec[i].size();j++) { if(vec[vec[i][j]].size()==1) cnt++; } if(vec[i].size()==2 && ok(vec[vec[i][0]]) && ok(vec[vec[i][1]])) flag=1 if(cnt>1) flag=1; } } if(flag) printf("First\n"); else printf("Second\n"); return 0; }
a.cc: In function 'int main()': a.cc:35:52: error: cannot convert 'std::vector<int>' to 'int' 35 | if(vec[i].size()==2 && ok(vec[vec[i][0]]) && ok(vec[vec[i][1]])) | ~~~~~~~~~~~~~^ | | | std::vector<int> a.cc:5:13: note: initializing argument 1 of 'bool ok(int)' 5 | bool ok(int x) | ~~~~^ a.cc:35:74: error: cannot convert 'std::vector<int>' to 'int' 35 | if(vec[i].size()==2 && ok(vec[vec[i][0]]) && ok(vec[vec[i][1]])) | ~~~~~~~~~~~~~^ | | | std::vector<int> a.cc:5:13: note: initializing argument 1 of 'bool ok(int)' 5 | bool ok(int x) | ~~~~^ a.cc:36:23: error: expected ';' before 'if' 36 | flag=1 | ^ | ; 37 | if(cnt>1) | ~~
s615472612
p03726
C++
#include <bits/stdc++.h> #define MAXN (100010) int n; int lfson[MAXN], sz[MAXN], deg[MAXN], f[MAXN], dep[MAXN]; int delta[MAXN]; std::vector<int> vec[MAXN]; struct cmp{ bool operator() (int a, int b){ return dep[a] < dep[b]; } }; std::priority_queue<int, std::vector<int>, cmp> pq; bool vis[MAXN]; void dfs(int u, int fa){ sz[u] = 1; for(auto v : vec[u]){ if(v == fa) continue; f[v] = u; dep[v] = dep[u] + 1; dfs(v, u); sz[u] += sz[v]; if(sz[v] == 1){ lfson[u] ++; pq.push(v); } } } int main(){ scanf("%d", &n); for(int i = 1; i < n; ++ i){ int u, v; scanf("%d%d", &u, &v); vec[u].push_back(v); vec[v].push_back(u); ++ deg[u]; ++ deg[v]; } for(int i = 1; i <= n; ++ i){ if(deg[i] != 1){ dfs(i, 0); break; } } while(!pq.empty()){ int u = pq.top(); pq.pop(); int v = f[u]; if(lfson[v] != 1){ return printf("First\n"), 0; } //v = f[v]; if(!f[v]) continue; delta[f[v]] += delta[u] + delta[v] + 2; sz[f[v]] -= delta[u] + delta[v] + 2; v = fa[v]; if(sz[v] == 1){ pq.push(v); if(f[v]){ lfson[f[v]] ++; } } } printf("Second\n"); return 0; }
a.cc: In function 'int main()': a.cc:60:21: error: 'fa' was not declared in this scope; did you mean 'fma'? 60 | v = fa[v]; | ^~ | fma
s172826862
p03726
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <string> #include <map> #include <set> #include <functional> #include <iostream> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; vector<int> G[100001]; int cnt[100001]; int e[100001]; bool used[100001]; bool used2[100001]; bool good[100001]; int rest; int dfs(int v){ used[v]=true; if(e[i]>=3){ used[v]=false; if(cnt[v]>=1)return 1; return -1000000; } for(int i=0;i<G[v].size();i++){ if(!used[G[v][i]] && !used2[G[v][i]]){ return (dfs(G[v][i])+1); } } } void dfs2(int v,int d){ used2[v]=true; if(e[i]>=3){ used2[v]=false; if(d%2==1)good[v]=true; return; } rest--; for(int i=0;i<G[v].size();i++){ if(!used2[G[v][i]]){ dfs2(G[v][i],d+1); } } } bool solve(){ if(rest==1)return true; memset(cnt,0,sizeof(cnt)); for(int i=0;i<n;i++){ if(e[i]==1 && !used2[i]){ cnt[G[i][0]]++; } } for(int i=0;i<n;i++){ if(cnt[i]>=2){ return true; } } int on=0,se=0; bool flag=true; for(int i=0;i<n;i++){ if(e[i]==1 && !used2[i]){ on++; } if(e[i]==2 && !used2[i]){ se++; } if(e[i]>2 && !used2[i]){ flag=false; } } if(flag && on==2 && se==n-2){ return (n%2==1); } for(int i=0;i<n;i++){ if(!used[i] && !used2[i] && e[i]==1){ if(dfs(i)==4){ return true; } } } memset(used,false,sizeof(used)); for(int i=0;i<n;i++){ if(cnt[i]==1 && !used2[i]){ for(int j=0;j<G[i].size();j++){ if(used[G[i][j]] && e[G[i][j]]==2){ return true; } used[G[i][j]]=true; } } } memset(good,false,sizeof(good)); for(int i=0;i<n;i++){ if(!used[i] && e[i]==1){ dfs2(i,0); } } bool flag2=false; for(int i=0;i<n;i++){ if(e[i]>=3 && !good[i]){ e[i]=1; flag2=true; } if(e[i]>=3 && good[i]){ return false; } } if(!flag2)return false; return solve(); } int main(void){ scanf("%d",&n); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); a--; b--; G[a].push_back(b); G[b].push_back(a); e[a]++; e[b]++; } printf("%s\n",solve()?"First":"Second"); return 0; }
a.cc: In function 'int dfs(int)': a.cc:29:14: error: 'i' was not declared in this scope 29 | if(e[i]>=3){ | ^ a.cc: In function 'void dfs2(int, int)': a.cc:43:14: error: 'i' was not declared in this scope 43 | if(e[i]>=3){ | ^ a.cc: In function 'int dfs(int)': a.cc:39:1: warning: control reaches end of non-void function [-Wreturn-type] 39 | } | ^
s643817374
p03726
C++
#include <iostream> #include <vector> #include <algorithm> using namespace std; class Tree { public: vector<int> edges; bool isLeaf() { return edges.size() == 1; } bool isBrunch() { return edges.size() == 2; } int brunchNextNode(int exept) { if (!isBrunch()) { return -1;} return edges[0] != exept ? edges[0] : edges[1]; } void setEdge(int n) { edges.push_back(n); } }; int main() { int N; cin >> N; vector<Tree> nodes(N+1); int a, b; for (int i=0; i<N-1; i++) { cin >> a >> b; nodes[a].setEdge(b); nodes[b].setEdge(a); } for (int i=1; i<=N; i++) { int tmp = 0; for (int j : nodes[i].edges) { tmp += nodes[j].isLeaf() ? 1 : 0; { tmp += 1; } else if (nodes[j].isBrunch()) { while (nodes[j].isBrunch()) { int k = nodes[j].brunchNextNode(j); j = nodes[k].brunchNextNode(k); } if (j == -1) { break; } if (nodes[j].isLeaf()) { tmp += 1; break; } } } if (tmp >= 2) { cout << "First" << endl; return 0; } } cout << "Second" << endl; return 0; }
a.cc: In function 'int main()': a.cc:35:15: error: 'else' without a previous 'if' 35 | } else if (nodes[j].isBrunch()) { | ^~~~
s063776167
p03726
C++
#define MYDEBUG #include <iostream> #include <vector> #include <chrono> #include <random> #include <algorithm> #include <map> #include <unordered_map> #include <cstdio> #include <queue> #include <stack> #include <cstring> #ifdef MYDEBUG #define debug(x) cout<<#x<<": "<<x<<endl #else #define debug(x) #endif #define ll long long #define ull unsigned long long #define eps 1e-14 #define all(x) x.begin(), x.end() #define umap unordered_map using namespace std; template<typename T> ostream& operator<<(ostream& out, const vector<T>& v) { out << "["; size_t last = v.size() - 1; for (size_t i = 0; i < v.size(); ++i) { out << v[i]; if (i != last) out << ","; } out << "]"; return out; } void solve() { int n; cin >> n; vector<vector<int> > g(n + 1); g[0] = 0; for (int i = 1; i <= n - 1; ++i) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } vector<int> cnt(n); //i番目の頂点が持つ, 次数1の子の数 //ノードjの次数は, g[j].size() for (int i = 1; i <= n; ++i) { for (size_t k = 0; k < g[i].size(); ++k) { int child = g[i][k]; if (g[child].size() == 1) { cnt[i]++; } } } for (int i = 1; i <= n; ++i) { if (cnt[i] >= 2) { cout << "First" << endl; return; } } cout << "Second" << endl; } int main() { solve(); return 0; }
a.cc: In function 'void solve()': a.cc:43:10: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} and 'int') 43 | g[0] = 0; | ^ In file included from /usr/include/c++/14/vector:72, from a.cc:3: /usr/include/c++/14/bits/vector.tcc:210:5: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(const std::vector<_Tp, _Alloc>&) [with _Tp = int; _Alloc = std::allocator<int>]' 210 | vector<_Tp, _Alloc>:: | ^~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/vector.tcc:211:42: note: no known conversion for argument 1 from 'int' to 'const std::vector<int>&' 211 | operator=(const vector<_Tp, _Alloc>& __x) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ In file included from /usr/include/c++/14/vector:66: /usr/include/c++/14/bits/stl_vector.h:766:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::vector<_Tp, _Alloc>&&) [with _Tp = int; _Alloc = std::allocator<int>]' 766 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ^~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:766:26: note: no known conversion for argument 1 from 'int' to 'std::vector<int>&&' 766 | operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move()) | ~~~~~~~~~^~~ /usr/include/c++/14/bits/stl_vector.h:788:7: note: candidate: 'std::vector<_Tp, _Alloc>& std::vector<_Tp, _Alloc>::operator=(std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>]' 788 | operator=(initializer_list<value_type> __l) | ^~~~~~~~ /usr/include/c++/14/bits/stl_vector.h:788:46: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<int>' 788 | operator=(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
s502350547
p03726
C++
#include<iostream> #include<vector> #include<map> #include<set> #include<algorithm> #include<numeric> #include<limits> #include<bitset> #include<functional> #include<type_traits> namespace lib { template<std::uint64_t Mod>struct modnum; template<class T>constexpr T pow(T base, std::size_t p) { if (p == 0) { return T(1); } else if (p == 1) { return base; } else if (p == 2) { return base*base; } else if (p % 2 == 0) { return pow(pow(base, p / 2), 2); } else { return pow(pow(base, p / 2), 2)*base; } } template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&); template<std::uint64_t Mod>struct modnum { static constexpr auto mod = Mod; std::uint64_t val; modnum() = default; constexpr modnum(std::uint64_t v) :val(v%Mod) { } constexpr modnum& operator+=(modnum const& v) { val += v.val; val %= mod; return *this; } constexpr modnum& operator-=(modnum const& v) { val += mod - v.val; val %= mod; return *this; } constexpr modnum& operator*=(modnum const& v) { val *= v.val; val %= mod; return *this; } constexpr modnum& operator/=(modnum const& v) { return operator*=(inverse(v)); } }; template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) { return lhs += rhs; } template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) { return lhs -= rhs; } template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) { return lhs *= rhs; } template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) { return lhs /= rhs; } template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base) { return pow(base, Mod - 2); } template<class T>constexpr auto clamp(T v) { return std::max(v, T()); } template<class T>void sort(std::vector<T>& vec) { std::sort(vec.begin(), vec.end()); } template<class T>auto lower_bound(std::vector<T>const& vec, T v) { return std::distance(vec.begin(), std::lower_bound(vec.begin(), vec.end(), v)); } template<class T>auto upper_bound(std::vector<T>const& vec, T v) { return std::distance(vec.begin(), std::upper_bound(vec.begin(), vec.end(), v)); } template<class Tag>struct dmod { std::uint64_t val; static std::uint64_t mod; dmod(std::uint64_t v = 0) :val(v%mod) { } dmod& operator+=(dmod const& rhs) { val += rhs.val; val %= mod; return *this; } dmod& operator-=(dmod const& rhs) { val += mod - rhs.val; val %= mod; return *this; } dmod& operator*=(dmod const& rhs) { val *= rhs.val; val %= mod; return *this; } }; template<class Tag>dmod<Tag> operator+(dmod<Tag> lhs, dmod<Tag> const& rhs) { return lhs += rhs; } template<class Tag>dmod<Tag> operator-(dmod<Tag> lhs, dmod<Tag> const& rhs) { return lhs -= rhs; } template<class Tag>dmod<Tag> operator*(dmod<Tag> lhs, dmod<Tag> const& rhs) { return lhs *= rhs; } template<class Tag>std::uint64_t dmod<Tag>::mod; struct scope_exit { std::function<void(void)> func; scope_exit(std::function<void(void)> f) :func(f) { } ~scope_exit() { func(); } }; template<int val>using int_tag = std::integral_constant<int, val>; } void Main(); int main() { std::cin.tie(nullptr); std::cin.sync_with_stdio(false); Main(); } bool check(std::vector<std::set<int>>const& edge, int now, int prev, int size) { if (edge[now].size() == 1 && *edge[now].begin == prev) { return size % 2 == 1; } for (auto const& v : edge[now]) { if (v == prev) { continue; } if (check(edge, v, now, size + 1)) return true; } return false; } void Main() { int N; std::cin >> N; std::vector<int> vec(N + 1, 0); std::vector<std::set<int>> edge(N + 1); for (int i = 0; i < N - 1; ++i) { int a, b; std::cin >> a >> b; if (vec[a] == 0) { vec[a] = b; } else { vec[a] = -1; } if (vec[b] == 0) { vec[b] = a; } else { vec[b] = -1; } edge[a].emplace(b); edge[b].emplace(a); } for (int i = 1; i <= N; ++i) { if (vec[i] > 0) { if (check(edge, i, -1, 1)) { std::cout << "First" << std::endl; return; } } } std::cout << "Second" << std::endl; }
a.cc:14:18: error: 'std::uint64_t' has not been declared 14 | template<std::uint64_t Mod>struct modnum; | ^~~ a.cc:38:18: error: 'std::uint64_t' has not been declared 38 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&); | ^~~ a.cc:38:66: error: 'Mod' was not declared in this scope 38 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&); | ^~~ a.cc:38:69: error: template argument 1 is invalid 38 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod> const&); | ^ a.cc:40:18: error: 'std::uint64_t' has not been declared 40 | template<std::uint64_t Mod>struct modnum | ^~~ a.cc:73:18: error: 'std::uint64_t' has not been declared 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:73:68: error: 'Mod' was not declared in this scope 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:73:71: error: template argument 1 is invalid 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:73:85: error: 'Mod' was not declared in this scope 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:73:88: error: template argument 1 is invalid 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:73:51: error: 'constexpr auto lib::operator+(int, const int&)' must have an argument of class or enumerated type 73 | template<std::uint64_t Mod>constexpr auto operator+(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~~~~~~ a.cc:77:18: error: 'std::uint64_t' has not been declared 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:77:68: error: 'Mod' was not declared in this scope 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:77:71: error: template argument 1 is invalid 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:77:85: error: 'Mod' was not declared in this scope 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:77:88: error: template argument 1 is invalid 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:77:51: error: 'constexpr auto lib::operator-(int, const int&)' must have an argument of class or enumerated type 77 | template<std::uint64_t Mod>constexpr auto operator-(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~~~~~~ a.cc:81:18: error: 'std::uint64_t' has not been declared 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:81:68: error: 'Mod' was not declared in this scope 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:81:71: error: template argument 1 is invalid 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:81:85: error: 'Mod' was not declared in this scope 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:81:88: error: template argument 1 is invalid 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:81:51: error: 'constexpr auto lib::operator*(int, const int&)' must have an argument of class or enumerated type 81 | template<std::uint64_t Mod>constexpr auto operator*(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~~~~~~ a.cc:85:18: error: 'std::uint64_t' has not been declared 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:85:68: error: 'Mod' was not declared in this scope 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:85:71: error: template argument 1 is invalid 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:85:85: error: 'Mod' was not declared in this scope 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~ a.cc:85:88: error: template argument 1 is invalid 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^ a.cc:85:51: error: 'constexpr auto lib::operator/(int, const int&)' must have an argument of class or enumerated type 85 | template<std::uint64_t Mod>constexpr auto operator/(modnum<Mod> lhs, modnum<Mod>const& rhs) | ^~~~~~~~ a.cc:90:18: error: 'std::uint64_t' has not been declared 90 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base) | ^~~ a.cc:90:66: error: 'Mod' was not declared in this scope 90 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base) | ^~~ a.cc:90:69: error: template argument 1 is invalid 90 | template<std::uint64_t Mod>constexpr auto inverse(modnum<Mod>const& base) | ^ a.cc: In function 'constexpr auto lib::inverse(const int&)': a.cc:92:34: error: 'Mod' was not declared in this scope 92 | return pow(base, Mod - 2); | ^~~ a.cc: At global scope: a.cc:116:22: error: 'uint64_t' in namespace 'std' does not name a type; did you mean 'wint_t'? 116 | std::uint64_t val; | ^~~~~~~~ | wint_t a.cc:117:29: error: 'uint64_t' in namespace 'std' does not name a type; did you mean 'wint_t'? 117 | static std::uint64_t mod; | ^~~~~~~~ | wint_t a.cc:118:35: error: expected ')' before 'v' 118 | dmod(std::uint64_t v = 0) :val(v%mod) | ~ ^~ | ) a.cc: In member function 'lib::dmod<Tag>& lib::dmod<Tag>::operator+=(const lib::dmod<Tag>&)': a.cc:124:25: error: 'val' was not declared in this scope 124 | val += rhs.val; | ^~~ a.cc:125:32: error: 'mod' was not declared in this scope; did you mean 'dmod'? 125 | val %= mod; | ^~~ | dmod a.cc: In member function 'lib::dmod<Tag>& lib::dmod<Tag>::operator-=(const lib::dmod<Tag>&)': a.cc:130:25: error: 'val' was not declared in this scope 130 | val += mod - rhs.val; | ^~~ a.cc:130:32: error: 'mod' was not declared in this scope; did you mean 'dmod'? 130 | val += mod - rhs.val; | ^~~ | dmod a.cc: In member function 'lib::dmod<Tag>& lib::dmod<Tag>::operator*=(const lib::dmod<Tag>&)': a.cc:136:25: error: 'val' was not declared in this scope 136 | val *= rhs.val; | ^~~ a.cc:137:32: error: 'mod' was not declared in this scope; did you mean 'dmod'? 137 | val %= mod; | ^~~ | dmod a.cc: At global scope: a.cc:153:33: error: 'uint64_t' in namespace 'std' does not name a type; did you mean 'wint_t'? 153 | template<class Tag>std::uint64_t dmod<Tag>::mod; | ^~~~~~~~ | wint_t a.cc: In function 'bool check(const std::vector<std::set<int> >&, int, int, int)': a.cc:181:49: error: invalid use of member function 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::begin() const [with _Key = int; _Compare = std::less<int>; _Alloc = std::alloca
s100610379
p03726
C++
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, cnt; vector <int> a[N]; bool vis[N] = {0}; int cou(int u) { int res = 0; for (int i = 0; i < a[u].size(); i++) { int v = a[u][i]; if (a[v].size() == 1) res++; } return res; } int dfs(int u) { vis[u] = true; cnt++; for (int i = 0; i < a[u].size(); i++) { int v = a[u][i]; if (!vis[v]) dfs(v); } } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, y; scanf("%d %d", &x, &y); a[x].push_back(y); a[y].push_back(x); } for (int i = 1; i <= n; i++) { if (cou(i) >= 2) { cout << "First" << endl; return 0; } } if (n & 1) { cout << "First" << endl; return 0; } vector <int> b; for (int i = 1; i <= n; i++) { if (a[i].size() >= 4) b.push_back(i); } int dem = 0; for (int t = 0; t < b.size(); t++) { int i = b[t]; dem += n; memset(vis, false, sizeof(vis)); if (deg[i] >= 4) { vis[i] = true; int res = 0; for (int j = 0; j < a[i].size(); j++) { cnt = 0; dfs(a[i][j]); res += cnt % 2; } if (res >= 2) { cout << "First" << endl; return 0; } } if (dem >= 200000000) break; } srand(time(NULL)); cout << "Second" << endl; }
a.cc: In function 'int dfs(int)': a.cc:25:1: warning: no return statement in function returning non-void [-Wreturn-type] 25 | } | ^ a.cc: In function 'int main()': a.cc:53:13: error: 'deg' was not declared in this scope; did you mean 'dem'? 53 | if (deg[i] >= 4) { | ^~~ | dem
s403792295
p03726
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <string> #include <map> #include <set> #include <functional> #include <iostream> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; vector<int> G[100001]; int cnt[100001]; int e[100001]; bool used[100001]; bool used2[100001]; bool good[100001]; int rest; int dfs(int v){ used[v]=true; if(G[v].size()>=3){ used[v]=false; if(cnt[v]>=1)return 1; return -1000000; } for(int i=0;i<G[v].size();i++){ if(!used[G[v][i]] && !used2[G[v][i]]){ return (dfs(G[v][i])+1); } } } void dfs2(int v,int d){ used2[v]=true; if(G[v].size()>=3){ used[v]=false; if(d%2==1)good[v]=true; return; } rest--; for(int i=0;i<G[v].size();i++){ if(!used2[G[v][i]]){ dfs2(G[v][i],d+1); } } } bool solve(){ if(rest==1)return true; memset(cnt,0,sizeof(cnt)); for(int i=0;i<n;i++){ if(e[i]==1){ cnt[G[i][0]]++; } } for(int i=0;i<n;i++){ if(cnt[i]>=2){ return true; } } int on=0,se=0; bool flag=true; for(int i=0;i<n;i++){ if(e[i]==1){ on++; } if(e[i]==2){ se++; } if(e[i]>2){ flag=false; } } if(flag && on==2 && se==n-2){ return (n%2==1); } for(int i=0;i<n;i++){ if(!used[i] && e[a]==1){ if(dfs(i)==4){ return true; } } } memset(used,false,sizeof(used)); for(int i=0;i<n;i++){ if(cnt[i]==1){ for(int j=0;j<G[i].size();j++){ if(used[G[i][j]] && G[G[i][j]].size()==2){ printf("First\n"); return 0; } used[G[i][j]]=true; } } } memset(good,false,sizeof(good)); for(int i=0;i<n;i++){ if(!used[i] && e[i]==1){ dfs2(i,0); } } for(int i=0;i<n;i++){ if(e[i]>=3 && !good[i]){ e[i]=1; } if(e[i]>=3 && good[i]){ return false; } } return true; } int main(void){ scanf("%d",&n); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); a--; b--; G[a].push_back(b); G[b].push_back(a); e[a]++; e[b]++; } printf("%s\n",solve()?"First":"Second"); return 0; }
a.cc: In function 'bool solve()': a.cc:86:34: error: 'a' was not declared in this scope 86 | if(!used[i] && e[a]==1){ | ^ a.cc: In function 'int dfs(int)': a.cc:39:1: warning: control reaches end of non-void function [-Wreturn-type] 39 | } | ^
s841018778
p03726
C++
#include <cstdio> #include <cstring> #include <vector> #include <queue> #include <string> #include <algorithm> #include <iostream> #include <string> #include <map> #include <set> #include <functional> #include <iostream> #define MOD 1000000007LL using namespace std; typedef long long ll; typedef pair<int,int> P; int n; vector<int> G[100001]; int cnt[100001]; int e[100001]; bool used[100001]; bool used2[100001]; bool good[100001]; int rest; int dfs(int v){ used[v]=true; if(G[v].size()>=3){ used[v]=false; if(cnt[v]>=1)return 1; return -1000000; } for(int i=0;i<G[v].size();i++){ if(!used[G[v][i]] && !used2[G[v][i]]){ return (dfs(G[v][i])+1); } } } void dfs2(int v,int d){ used2[v]=true; if(G[v].size()>=3){ used[v]=false; if(d%2==1)good[v]=true; return; } rest--; for(int i=0;i<G[v].size();i++){ if(!used2[G[v][i]]){ dfs2(G[v][i],d+1); } } } bool solve(){ if(rest==1)return true; memset(cnt,0,sizeof(cnt)); for(int i=0;i<n;i++){ if(e[i]==1){ cnt[G[i][0]]++; } } for(int i=0;i<n;i++){ if(cnt[i]>=2){ return true; } } int on=0,se=0; bool flag=true; for(int i=0;i<n;i++){ if(e[i]==1){ on++; } if(e[i]==2){ se++; } if(e[i]>2){ flag=false; } } if(flag && on==2 && se==n-2){ return (n%2==1); } for(int i=0;i<n;i++){ if(!used[i] && e[a]==1){ if(dfs(i)==4){ return true; } } } memset(used,false,sizeof(used)); for(int i=0;i<n;i++){ if(cnt[i]==1){ for(int j=0;j<G[i].size();j++){ if(used[G[i][j]] && G[G[i][j]].size()==2){ printf("First\n"); return 0; } used[G[i][j]]=true; } } } memset(good,false,sizeof(good)); for(int i=0;i<n;i++){ if(!used[i] && e[i]==1){ dfs2(i,0); } } for(int i=0;i<n;i++){ if(e[i]>=3 && !good[i]){ e[i]=1; } if(e[i]>=3 && good[i]){ return false; } } return solve(); } int main(void){ scanf("%d",&n); for(int i=0;i<n-1;i++){ int a,b; scanf("%d%d",&a,&b); a--; b--; G[a].push_back(b); G[b].push_back(a); e[a]++; e[b]++; } printf("%s\n",solve()?"First":"Second"); return 0; }
a.cc: In function 'bool solve()': a.cc:86:34: error: 'a' was not declared in this scope 86 | if(!used[i] && e[a]==1){ | ^ a.cc: In function 'int dfs(int)': a.cc:39:1: warning: control reaches end of non-void function [-Wreturn-type] 39 | } | ^
s212716559
p03726
C++
//In the Name of God //Let Our Voices Echo #pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; #define X real() #define Y imag() typedef long long ll; typedef double ld; typedef complex<ld> point; const ld eps=1e-9; const int MAX=1e5+9,MOD=1e9+7; int n,d[MAX]; vector<int> g[MAX]; queue<int> q; int main() { ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); memset(d,-1,sizeof d); cin>>n; if (n==2) return cout<<"Second",0; for (int i=1,v,u;i<n;i++) { cin>>v>>u,v--,u--,g[v].push_back(u),g[u].push_back(v); } for (int i=0;i<n;i++) if (g[i].size()==1) q.push(i),d[i]=0; while (q.size()) { int v=q.front(); q.pop(); for (auto u:g[v]) if (d[u]==-1) d[u]=d[v]+1,q.push(u); } int mx=*max_element(d,d+n),cnt=0; for (int i=0;i<n;i++) if (d[i]==mx) cnt++; if (cnt==1) return cout<<"First",0; for (int i=0;i<n;i++) { int cnt=0; for (auto u:g[i]) if (d[u]==d[i]-1) cnt++; if (cnt>1) return cout<<"First",0; } if (mx%2==1) return cout<<"Second",0; cout<<"First"<<Endl; }
a.cc: In function 'int main()': a.cc:49:24: error: 'Endl' was not declared in this scope 49 | cout<<"First"<<Endl; | ^~~~