submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s953337835
p03716
C++
#include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #include<iostream> #include<queue> using namespace std; priority_queue<int>QD; priority_queue<int,vector<int>,greater<int> >QU; typedef long long ll; int n; int a[310000]; ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); int main(){ scanf("%d",&n); for(int i=1;i<=3*n;i++){ scanf("%d",&a[i]); }for(int i=1;i<=n;i++){ smx+=a[i]; QU.push(a[i]); } pmx[n]=smx; for(int i=n+1;i<=2*n;i++){ if(a[i]>QU.top()){ smx-=QU.top(); QU.pop(); smx+=a[i]; QU.push(a[i]); } pmx[i]=smx; } for(int i=3*n;i>2*n;i--){ smn+=a[i]; QD.push(a[i]); } qmn[2*n+1]=smn; for(int i=2*n;i>=n;i--){ if(a[i]<QD.top()){ smn-=QD.top(); QD.pop(); smn+=a[i]; QD.push(a[i]); } qmn[i]=smn; } for(int i=n;i<=2*n;i++){ ans=max(ans,pmx[i]-qmn[i+1]); } printf("%lld\n",ans); return 0; }#include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #include<iostream> #include<queue> using namespace std; priority_queue<int>QD; priority_queue<int,vector<int>,greater<int> >QU; typedef long long ll; int n; int a[310000]; ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); int main(){ scanf("%d",&n); for(int i=1;i<=3*n;i++){ scanf("%d",&a[i]); }for(int i=1;i<=n;i++){ smx+=a[i]; QU.push(a[i]); } pmx[n]=smx; for(int i=n+1;i<=2*n;i++){ if(a[i]>QU.top()){ smx-=QU.top(); QU.pop(); smx+=a[i]; QU.push(a[i]); } pmx[i]=smx; } for(int i=3*n;i>2*n;i--){ smn+=a[i]; QD.push(a[i]); } qmn[2*n+1]=smn; for(int i=2*n;i>=n;i--){ if(a[i]<QD.top()){ smn-=QD.top(); QD.pop(); smn+=a[i]; QD.push(a[i]); } qmn[i]=smn; } for(int i=n;i<=2*n;i++){ ans=max(ans,pmx[i]-qmn[i+1]); } printf("%lld\n",ans); return 0; }
a.cc:54:2: error: stray '#' in program 54 | }#include<stdio.h> | ^ a.cc:54:3: error: 'include' does not name a type 54 | }#include<stdio.h> | ^~~~~~~ a.cc:62:20: error: redefinition of 'std::priority_queue<int> QD' 62 | priority_queue<int>QD; | ^~ a.cc:9:20: note: 'std::priority_queue<int> QD' previously declared here 9 | priority_queue<int>QD; | ^~ a.cc:63:46: error: redefinition of 'std::priority_queue<int, std::vector<int, std::allocator<int> >, std::greater<int> > QU' 63 | priority_queue<int,vector<int>,greater<int> >QU; | ^~ a.cc:10:46: note: 'std::priority_queue<int, std::vector<int, std::allocator<int> >, std::greater<int> > QU' previously declared here 10 | priority_queue<int,vector<int>,greater<int> >QU; | ^~ a.cc:66:5: error: redefinition of 'int n' 66 | int n; | ^ a.cc:13:5: note: 'int n' previously declared here 13 | int n; | ^ a.cc:67:5: error: redefinition of 'int a [310000]' 67 | int a[310000]; | ^ a.cc:14:5: note: 'int a [310000]' previously declared here 14 | int a[310000]; | ^ a.cc:68:4: error: redefinition of 'll pmx [310000]' 68 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:15:4: note: 'll pmx [310000]' previously declared here 15 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:68:16: error: redefinition of 'll qmn [310000]' 68 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:15:16: note: 'll qmn [310000]' previously declared here 15 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:68:28: error: redefinition of 'll smx' 68 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:15:28: note: 'll smx' previously declared here 15 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:68:32: error: redefinition of 'll smn' 68 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:15:32: note: 'll smn' previously declared here 15 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:68:36: error: redefinition of 'll ans' 68 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:15:36: note: 'll ans' previously defined here 15 | ll pmx[310000],qmn[310000],smx,smn,ans=-(1ll<<60); | ^~~ a.cc:70:5: error: redefinition of 'int main()' 70 | int main(){ | ^~~~ a.cc:17:5: note: 'int main()' previously defined here 17 | int main(){ | ^~~~
s627578104
p03716
C++
#include<stdio.h> #include<string.h> #include<iostream> #include<string> #include<algorithm> #include<vector> #include<map> #include<unordered_set> #include<unordered_map> #include<math.h> #include<queue> #include<functional> #include<limits.h> #include<set> #define int long long using namespace std; int c[300000]; vector<int>X, Y; signed main() { priority_queue<int, vector<int>, greater<int>>Q; int a; cin >> a; if(N<=1000)return 0; for (int b = 0; b < 3 * a; b++) { scanf("%lld", &c[b]); } int sum = 0; for (int i = 0; i < 2 * a; i++) { Q.push(c[i]); sum += c[i]; if (Q.size() == a + 1) { sum -= Q.top(); Q.pop(); } if (Q.size() == a) { X.push_back(sum); } } priority_queue<int>P; sum = 0; for (int i = 3 * a - 1; i >= a; i--) { P.push(c[i]); sum += c[i]; if (P.size() == a + 1) { sum -= P.top(); P.pop(); } if (P.size() == a) { Y.push_back(sum); } } reverse(Y.begin(), Y.end()); int ans = LLONG_MIN; for (int i = 0; i <= a; i++) { ans = max(ans, X[i] - Y[i]); } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:23:4: error: 'N' was not declared in this scope 23 | if(N<=1000)return 0; | ^
s907273414
p03716
C++
#include <iostream> #include <queue> #include <type_traits> #include <functional> #include <algorithm> using ll=long long int; constexpr int MAX_N=(int)1e5; constexpr ll INF=-(int)1e15; template<bool B> using Q = std::priority_queue<int,std::vector<int>,std::conditional_t<B,std::greater<>,std::less<>>>; Q<true> firstHalf; Q<false> secondHalf; ll f[MAX_N*3],s[MAX_N*3]; int n; int a[MAX_N*3]; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); std::cin>>n; for(int i=0;i<n*3;++i) std::cin>>a[i]; ll res = 0; for(int i=0;i<n*3;++i){ if(i<n){ firstHalf.emplace(a[i]); res+=a[i]; } else if(firstHalf.top()<a[i]){ res+=a[i]-firstHalf.top(); firstHalf.emplace(a[i]); firstHalf.pop(); } f[i]=res; } res=0; for(int i=n*3-1;i>=0;--i){ if(i>=n*2){ secondHalf.emplace(a[i]); res+=a[i]; } else if(secondHalf.top()>a[i]){ res+=a[i]-secondHalf.top(); secondHalf.emplace(a[i]); secondHalf.pop(); } s[i]=res; } ll ans=INF; for(int i=n-1;i<n*2;++i){ ans=std::max(ans,f[i]-s[i+1]); } std::cout<<ans<<std::endl; return 0; }
a.cc:11:18: error: overflow in constant expression [-fpermissive] 11 | constexpr ll INF=-(int)1e15; | ^~~~~~~~~~ a.cc:11:24: error: overflow in constant expression [-fpermissive] 11 | constexpr ll INF=-(int)1e15; | ^~~~
s673550993
p03716
C++
#include <iostream> #include <stdio.h> #include <cstring> using namespace std; int main() { long long n = 0; cin >> n; long long* a = new long long [3*n]; for(long long i = 0; i < 3*n; i++){ cin >> a[i]; } long long compare = 0; for(long long i = 0; i < 2*n){ for(long long ii = i + 1; ii < 2*n; ii++){ for(long long iii = ii + 1; iii < 2*n; iii++){ for(long long j = iii + 1; j < 3*n; j++){ for(long long jj = j + 1; jj < 3*n; jj++){ for(long long jjj = jj + 1; jjj < 3*n; jjj++){ if(i + ii + iii - j - jj - jjj > compare){ compare = i + ii + iii - j - jj - jjj; } } } } } } } cout << compare; }
a.cc: In function 'int main()': a.cc:20:37: error: expected ';' before ')' token 20 | for(long long i = 0; i < 2*n){ | ^ | ;
s084687641
p03716
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #include <list> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } class Bitvector { //4byteブロック 全部半径、0-index const int bsize = 8; static const int popc[256]; public: unsigned char* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned char*)calloc((n + bsize - 1) / bsize, sizeof(char)); blockrank = (unsigned int*)calloc((n + bsize - 1) / bsize + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / bsize], (bsize - 1 - a % bsize)); } inline bool get(int a) { return bitcheck(st[a / bsize], (bsize - 1 - a % bsize)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 8))blockrank[i / bsize] = cou; if (i<sz)cou += bitcheck(st[i / bsize], (bsize - 1 - i % bsize)); } } int rank(int a, bool t) { int ret = blockrank[a / bsize] + (((bsize - a % bsize) >= bsize) ? 0 : popc[st[a / bsize] >> (bsize - a % bsize)]); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; const int Bitvector::popc[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) 数値比較系使うときはunsignedのみ!!!!! template<typename T> class WaveletMatrix { #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= ((T)1 << b)) #define bitunset(a,b) (a &= ~((T)1 << b)) public: vector<T> data,rui; vector<vector<T>> bitrui; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat), border(sizeof(T) * 8 +1), rui(data.size()+1), bitrui(sizeof(T)*8) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); REP(j, data.size()) { bitv[0].set(j, bitcheck(data[j], bitsize - 1)); rui[j+1] = rui[j] + data[j]; } bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; bitrui[i].resize(data.size()+1); REP(j, data.size()) { bitrui[i][j + 1] = bitcheck(buf[i % 2][j], bitsize - i - 1) * buf[i % 2][j] + bitrui[i][j]; bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = bitunset(buf[i % 2][j], (bitsize - i - 1)); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } bitrui[bitsize-1].resize(data.size()+1); REP(j, data.size()) { bitrui[bitsize-1][j + 1] = bitcheck(buf[(bitsize - 1) % 2][j], 0) * buf[(bitsize - 1) % 2][j] + bitrui[bitsize-1][j]; } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T less_kthelement(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? less_kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : less_kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } T more_kthelement(int s, int e, int k, int b = 0) {//上からk個のsum 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return cou > k; return (cou > k ? more_kthelement(border[b + 1]+so, border[b + 1]+ so + cou, k, b + 1) : more_kthelement(s-so, (s - so) + (e - s - cou), k - cou, b + 1)) | ((cou > k) << (bitsize - b - 1)); } pair<T,T> more_kthsum(int s, int e, int k, int b = 0) {//大きいほうから 0番目~ if (k < 0) return { 0,0 }; int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return { min(1 + k,cou),1 }; if (cou > k) { pair<T,T> ret = more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, k, b + 1); return {ret.first + (T)min(k + 1, cou) * ret.second * 2, ret.second * 2}; } else { pair<T,T> ret = more_kthsum(s - so, (s - so) + (e - s - cou), k - cou, b + 1); return { ret.first + (bitrui[b+1][border[b+1] + so + cou] - bitrui[b+1][border[b+1] + so]) + (T)min(k + 1, cou) * ret.second * 2, ret.second * 2}; } } T less_kthsum(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ return (rui[e] - rui[s]) - more_kthsum(s, e, (e - s) - k - 2).first; } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n; scanf("%d", &n); vector<__uint128> num(n*3); REP(i, n*3) { scnaf("%lld", &num[i]); } WaveletMatrix<__uint128> wv(num); __uint128 Max = LLONG_MIN; rep(i, n, n*2+1) { __uint128 b = wv.more_kthsum(0, i, n - 1).first, c = wv.less_kthsum(i, n * 3, n - 1); Max = max(Max, b - c); } printf("%lld\n", Max); return 0; }
a.cc:108:9: warning: "bitset" redefined 108 | #define bitset(a,b) ( a |= ((T)1 << b)) | ^~~~~~ a.cc:30:9: note: this is the location of the previous definition 30 | #define bitset(a,b) ( a |= (1 << b)) | ^~~~~~ a.cc:109:9: warning: "bitunset" redefined 109 | #define bitunset(a,b) (a &= ~((T)1 << b)) | ^~~~~~~~ a.cc:31:9: note: this is the location of the previous definition 31 | #define bitunset(a,b) (a &= ~(1 << b)) | ^~~~~~~~ a.cc: In function 'int main()': a.cc:222:16: error: '__uint128' was not declared in this scope; did you mean '__int128'? 222 | vector<__uint128> num(n*3); | ^~~~~~~~~ | __int128 a.cc:222:25: error: template argument 1 is invalid 222 | vector<__uint128> num(n*3); | ^ a.cc:222:25: error: template argument 2 is invalid a.cc:224:35: error: invalid types 'int[int]' for array subscript 224 | scnaf("%lld", &num[i]); | ^ a.cc:229:18: error: expected ';' before 'Max' 229 | __uint128 Max = LLONG_MIN; | ^~~~ | ; a.cc:232:26: error: expected ';' before 'b' 232 | __uint128 b = wv.more_kthsum(0, i, n - 1).first, c = wv.less_kthsum(i, n * 3, n - 1); | ^~ | ; a.cc:233:17: error: 'Max' was not declared in this scope 233 | Max = max(Max, b - c); | ^~~ a.cc:233:32: error: 'b' was not declared in this scope 233 | Max = max(Max, b - c); | ^ a.cc:233:36: error: 'c' was not declared in this scope 233 | Max = max(Max, b - c); | ^ a.cc:235:26: error: 'Max' was not declared in this scope 235 | printf("%lld\n", Max); | ^~~
s440565043
p03716
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #include <list> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } class Bitvector { //4byteブロック 全部半径、0-index const int bsize = 8; static const int popc[256]; public: unsigned char* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned char*)calloc((n + bsize - 1) / bsize, sizeof(char)); blockrank = (unsigned int*)calloc((n + bsize - 1) / bsize + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / bsize], (bsize - 1 - a % bsize)); } inline bool get(int a) { return bitcheck(st[a / bsize], (bsize - 1 - a % bsize)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 8))blockrank[i / bsize] = cou; if (i<sz)cou += bitcheck(st[i / bsize], (bsize - 1 - i % bsize)); } } int rank(int a, bool t) { int ret = blockrank[a / bsize] + (((bsize - a % bsize) >= bsize) ? 0 : popc[st[a / bsize] >> (bsize - a % bsize)]); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; const int Bitvector::popc[256] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T less_kthelement(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? less_kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : less_kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } T more_kthelement(int s, int e, int k, int b = 0) {//上からk個のsum 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return cou > k; return (cou > k ? more_kthelement(border[b + 1]+so, border[b + 1]+ so + cou, k, b + 1) : more_kthelement(s-so, (s - so) + (e - s - cou), k - cou, b + 1)) | ((cou > k) << (bitsize - b - 1)); } pair<ll, int> more_kthsum(int s, int e, int k, int b = 0) {//大きいほうから 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return { min(1 + k,cou),1 }; if (cou > k) { pair<ll, int> ret = more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, k, b + 1); return {ret.first + min(k + 1, cou) * ret.second * 2, ret.second * 2}; } else { pair<ll, int> ret = (cou ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, cou - 1, b + 1) : pair<T,T>()), ret2 = more_kthsum(s - so, (s - so) + (e - s - cou), k - cou, b + 1); return { ret.first + ret2.first + min(k + 1, cou) * ret2.second * 2, ret2.second * 2}; } } pair<ll, int> less_kthsum(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return { max(0, (k + 1) - cou), 1}; if (cou <= k) { pair<ll, int> ret = less_kthsum(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1), ret2 = less_kthsum(so, so + cou, cou - 1, b + 1); return { ret.first + ret2.first + max(0, (k + 1) - cou) * ret.second * 2 , ret.second*2}; } else { pair<ll, int> ret = less_kthsum(so, so + cou, k, b + 1); return {ret.first + max(0, (k + 1) - cou) * ret.second * 2, ret.second * 2 }; } } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n; scanf("%d", &n); vector<int> num(n*3); REP(i, n*3) { scnaf("%d", &num[i]); } WaveletMatrix<int> wv(num); ll Max = LLONG_MIN; rep(i, n, n*2+1) { ll b = wv.more_kthsum(0, i, n - 1).first, c = wv.less_kthsum(i, n * 3, n - 1).first; Max = max(Max, b - c); } printf("%lld\n", Max); return 0; }
a.cc: In instantiation of 'std::pair<long long int, int> WaveletMatrix<T>::more_kthsum(int, int, int, int) [with T = int]': a.cc:230:24: required from here 230 | ll b = wv.more_kthsum(0, i, n - 1).first, c = wv.less_kthsum(i, n * 3, n - 1).first; | ~~~~~~~~~~~~~~^~~~~~~~~~~~~ a.cc:183:51: error: operands to '?:' have different types 'std::pair<long long int, int>' and 'std::pair<int, int>' 183 | pair<ll, int> ret = (cou ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, cou - 1, b + 1) : pair<T,T>()), | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:183:51: note: and each type can be converted to the other
s737583828
p03716
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #include <list> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } class Bitvector { //4byteブロック 全部半径、0-index static const int mask[32]; public: unsigned int* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned int*)calloc((n + 31) / 32, sizeof(int)); blockrank = (unsigned int*)calloc((n + 31) / 32 + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / 32], (31 - a % 32)); } inline bool get(int a) { return bitcheck(st[a / 32], (31 - a % 32)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 32))blockrank[i / 32] = cou; if (i<sz)cou += bitcheck(st[i / 32], (31 - i % 32)); } } int rank(int a, bool t) { int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T less_kthelement(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? less_kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : less_kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } T more_kthelement(int s, int e, int k, int b = 0) {//上からk個のsum 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return cou > k; return (cou > k ? more_kthelement(border[b + 1]+so, border[b + 1]+ so + cou, k, b + 1) : more_kthelement(s-so, (s - so) + (e - s - cou), k - cou, b + 1)) | ((cou > k) << (bitsize - b - 1)); } T more_kthsum(int s, int e, int k, int b = 0) {//大きいほうから 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return min(1+k,cou); return (cou > k ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, k, b + 1) : (cou ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, cou - 1, b + 1) : 0)+ more_kthsum(s - so, (s - so) + (e - s - cou), k - cou, b + 1)) + min(k+1,cou) * pow(2, bitsize - b - 1); } T less_kthsum(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return max(0, (k+1) - cou); return (cou <= k ? (less_kthsum(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) + less_kthsum(so, so + cou, cou-1, b + 1) ) : less_kthsum(so, so + cou, k, b + 1)) + max(0, (k + 1) - cou) * pow(2, bitsize - b - 1); } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n; scanf("%d", &n); vector<ll> num(n*3); REP(i, n*3) { scnaf("%d", &num[i]); } WaveletMatrix<ll> wv(num); ll Max = LLONG_MIN; rep(i, n, n*2) { ll b = wv.more_kthsum(0, i, n - 1), c = wv.less_kthsum(i, n * 3, n - 1); Max = max(Max, b - c); } printf("%d\n", Max); return 0; }
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/include/smmintrin.h:812, from /usr/lib/gcc/x86_64-linux-gnu/14/include/nmmintrin.h:31, from a.cc:18: /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h: In member function 'int Bitvector::rank(int, bool)': /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h:35:1: error: inlining failed in call to 'always_inline' 'int _mm_popcnt_u32(unsigned int)': target specific option mismatch 35 | _mm_popcnt_u32 (unsigned int __X) | ^~~~~~~~~~~~~~ a.cc:82:90: note: called from here 82 | int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s604678866
p03716
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #include <list> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } class Bitvector { //4byteブロック 全部半径、0-index static const int mask[32]; public: unsigned int* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned int*)calloc((n + 31) / 32, sizeof(int)); blockrank = (unsigned int*)calloc((n + 31) / 32 + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / 32], (31 - a % 32)); } inline bool get(int a) { return bitcheck(st[a / 32], (31 - a % 32)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 32))blockrank[i / 32] = cou; if (i<sz)cou += bitcheck(st[i / 32], (31 - i % 32)); } } int rank(int a, bool t) { int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T less_kthelement(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? less_kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : less_kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } T more_kthelement(int s, int e, int k, int b = 0) {//上からk個のsum 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return cou > k; return (cou > k ? more_kthelement(border[b + 1]+so, border[b + 1]+ so + cou, k, b + 1) : more_kthelement(s-so, (s - so) + (e - s - cou), k - cou, b + 1)) | ((cou > k) << (bitsize - b - 1)); } T more_kthsum(int s, int e, int k, int b = 0) {//大きいほうから 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return min(1+k,cou); return (cou > k ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, k, b + 1) : (cou ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, cou - 1, b + 1) : 0)+ more_kthsum(s - so, (s - so) + (e - s - cou), k - cou, b + 1)) + min(k+1,cou) * pow(2, bitsize - b - 1); } T less_kthsum(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return max(0, (k+1) - cou); return (cou <= k ? (less_kthsum(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) + less_kthsum(so, so + cou, cou-1, b + 1) ) : less_kthsum(so, so + cou, k, b + 1)) + max(0, (k + 1) - cou) * pow(2, bitsize - b - 1); } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n; scanf("%d", &n); vector<ll> num(n*3); REP(i, n*3) { scnaf("%d", &num[i]); } WaveletMatrix<ll> wv(num); ll Max = LLONG_MIN; rep(i, n, n*2) { ll b = wv.more_kthsum(0, i, n - 1), c = wv.less_kthsum(i, n * 3, n - 1); Max = max(Max, b - c); } printf("%d\n", Max); return 0; }
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/include/smmintrin.h:812, from /usr/lib/gcc/x86_64-linux-gnu/14/include/nmmintrin.h:31, from a.cc:18: /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h: In member function 'int Bitvector::rank(int, bool)': /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h:35:1: error: inlining failed in call to 'always_inline' 'int _mm_popcnt_u32(unsigned int)': target specific option mismatch 35 | _mm_popcnt_u32 (unsigned int __X) | ^~~~~~~~~~~~~~ a.cc:82:90: note: called from here 82 | int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s182552307
p03716
C++
#include <iostream> #include <cstdio> #include <vector> #include <cmath> #include <cstring> #include <numeric> #include <algorithm> #include <functional> #include <array> #include <map> #include <queue> #include <limits.h> #include <set> #include <stack> #include <random> #include <complex> #include <unordered_map> #include <nmmintrin.h> #include <chrono> #include <list> #define rep(i,s,n) for(int i = (s); (n) > i; i++) #define REP(i,n) rep(i,0,n) #define RANGE(x,a,b) ((a) <= (x) && (x) <= (b)) #define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b)) #define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d)) #define PW(x) ((x)*(x)) #define ALL(x) (x).begin(), (x).end() #define MODU 1000000007 #define bitcheck(a,b) ((a >> b) & 1) #define bitset(a,b) ( a |= (1 << b)) #define bitunset(a,b) (a &= ~(1 << b)) #define MP(a,b) make_pair((a),(b)) #define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second)) #define pritnf printf #define scnaf scanf #define itn int #define PI 3.141592653589 #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a%b); } template<typename A, size_t N, typename T> void Fill(A(&array)[N], const T &val) { std::fill((T*)array, (T*)(array + N), val); } #ifdef _MSC_VER #define __builtin_popcount _mm_popcnt_u32 #define __builtin_popcountll _mm_popcnt_u64 #endif class Bitvector { //4byteブロック 全部半径、0-index static const int mask[32]; public: unsigned int* st; unsigned int* blockrank; int sz; Bitvector(int n) { sz = n; st = (unsigned int*)calloc((n + 31) / 32, sizeof(int)); blockrank = (unsigned int*)calloc((n + 31) / 32 + 1, sizeof(int)); if (st == NULL || blockrank == NULL) abort(); } inline void set(int a, bool f) {//後から追加はできない if (f)bitset(st[a / 32], (31 - a % 32)); } inline bool get(int a) { return bitcheck(st[a / 32], (31 - a % 32)); } inline void calcblock() { int cou = 0; REP(i, sz + 1) { if (i && !(i % 32))blockrank[i / 32] = cou; if (i<sz)cou += bitcheck(st[i / 32], (31 - i % 32)); } } int rank(int a, bool t) { int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); return t ? ret : a - ret; } int select(int a, bool t) { int l = 0, r = sz + 1; while (r - l > 1) { int mid = (l + r) / 2; if (rank(mid, t) >= a) r = mid; else l = mid; } if (rank(r, t) < a) return -1; return r; } void clear() { free(st); free(blockrank); } }; //プリミティブ型だけだよ!!!!(低レベルでうぇぶるので) template<typename T> class WaveletMatrix { public: vector<T> data; vector<Bitvector> bitv; vector<int> border; int bitsize; WaveletMatrix(vector<T>& dat) : bitsize(sizeof(T) * 8), data(dat) { bitv.reserve(bitsize); REP(i, bitsize + 1) bitv.push_back(Bitvector(data.size())); border.resize(bitsize + 1); REP(j, data.size()) bitv[0].set(j, bitcheck(data[j], bitsize - 1)); bitv[0].calcblock(); vector<T> buf[2]; buf[0] = data; buf[1].resize(data.size()); REP(i, bitsize - 1) { border[i + 1] = bitv[i].rank(data.size(), 0); int cou[2] = { 0, border[i + 1] }; REP(j, data.size()) { bitv[i + 1].set(cou[bitv[i].get(j)], bitcheck(buf[i % 2][j], bitsize - i - 2)); buf[1 - i % 2][cou[bitv[i].get(j)]] = buf[i % 2][j] << (i + 1) >> (i + 1); cou[bitv[i].get(j)]++; } bitv[i + 1].calcblock(); } border[bitsize] = bitv[bitsize - 1].rank(data.size(), 0); } pii search(int s, int e, unsigned int t, int b = 0) { if (b == bitsize) return{ s,e }; bool cur = bitcheck(t, bitsize - 1); return search(cur*border[b + 1] + bitv[b].rank(s, cur), cur*border[b + 1] + bitv[b].rank(e, cur), t << 1, b + 1); } int backward(int a, unsigned int t, int b = 0) { if (b == bitsize - 1) return a; backward(bitv[bitsize - b - 1].select(a + 1 - bitcheck(t, 0) * border[bitsize - b], bitcheck(t, 0)) - 1, t >> 1, b + 1); } int rank(int s, int e, T t) { pii r = search(s, e, t); return r.second - r.first; } int select(int a, T t) { pii r = search(0, data.size(), t); return backward(r.first + a - 1, t); } T less_kthelement(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return cou <= k; return (cou <= k ? less_kthelement(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) : less_kthelement(so, so + cou, k, b + 1)) | ((cou <= k) << (bitsize - b - 1)); } T more_kthelement(int s, int e, int k, int b = 0) {//上からk個のsum 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return cou > k; return (cou > k ? more_kthelement(border[b + 1]+so, border[b + 1]+ so + cou, k, b + 1) : more_kthelement(s-so, (s - so) + (e - s - cou), k - cou, b + 1)) | ((cou > k) << (bitsize - b - 1)); } T more_kthsum(int s, int e, int k, int b = 0) {//大きいほうから 0番目~ int eo = bitv[b].rank(e, 1), so = bitv[b].rank(s, 1), cou = eo - so; if (b == bitsize - 1) return min(1+k,cou); return (cou > k ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, k, b + 1) : (cou ? more_kthsum(border[b + 1] + so, border[b + 1] + so + cou, cou - 1, b + 1) : 0)+ more_kthsum(s - so, (s - so) + (e - s - cou), k - cou, b + 1)) + min(k+1,cou) * pow(2, bitsize - b - 1); } T less_kthsum(int s, int e, int k, int b = 0) {//小さいほうから 0番目~ int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = eo - so; if (b == bitsize - 1) return max(0, (k+1) - cou); return (cou <= k ? (less_kthsum(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), k - cou, b + 1) + less_kthsum(so, so + cou, cou-1, b + 1) ) : less_kthsum(so, so + cou, k, b + 1)) + max(0, (k + 1) - cou) * pow(2, bitsize - b - 1); } int less(int s, int e, T t, int b = 0) { int eo = bitv[b].rank(e, 0), so = bitv[b].rank(s, 0), cou = (eo - so); if (b == bitsize) return e - s; return bitcheck(t, bitsize - b - 1) ? less(border[b + 1] + (s - so), border[b + 1] + (s - so) + (e - s - cou), t, b + 1) + cou : less(so, so + cou, t, b + 1); } ~WaveletMatrix() { REP(i, bitsize) bitv[i].clear(); } }; signed main() { int n; scanf("%d", &n); vector<ll> num(n*3); REP(i, n*3) { scnaf("%d", &num[i]); } WaveletMatrix<ll> wv(num); ll Max = LLONG_MIN; rep(i, n, n*2) { ll b = wv.more_kthsum(0, i, n - 1), c = wv.less_kthsum(i, n * 3, n - 1); Max = max(Max, b - c); } printf("%d\n", Max); return 0; }
In file included from /usr/lib/gcc/x86_64-linux-gnu/14/include/smmintrin.h:812, from /usr/lib/gcc/x86_64-linux-gnu/14/include/nmmintrin.h:31, from a.cc:18: /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h: In member function 'int Bitvector::rank(int, bool)': /usr/lib/gcc/x86_64-linux-gnu/14/include/popcntintrin.h:35:1: error: inlining failed in call to 'always_inline' 'int _mm_popcnt_u32(unsigned int)': target specific option mismatch 35 | _mm_popcnt_u32 (unsigned int __X) | ^~~~~~~~~~~~~~ a.cc:88:90: note: called from here 88 | int ret = blockrank[a / 32] + (((32 - a % 32) >= 32) ? 0 : _mm_popcnt_u32(st[a / 32] >> (32 - a % 32))); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
s831127407
p03716
C++
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> #include <stdio.h> #include <string.h> #include <math.h> using namespace std; template <class C> struct SegmentTree { struct Node { Node operator+(const Node& o) const { return *this < o ? *this : o; } bool operator<(const Node& o) const { return C()(v, o.v); } int v, i; }; SegmentTree(int n, Node& o) : n(n) { for (m = 2; m < n; m *= 2); data = vector<Node>(m + n, o); } void construct() { int l = m + n; for (int k = m; k > 1; k /= 2) { l = (l + 1) / 2; for (int i = k / 2; i < l; i++) { data[i] = data[i * 2] + data[i * 2 + 1]; } } } void update(int i, Node& o) { for (data[i += m] = o; i /= 2, i > 0;) data[i] = data[i * 2] + data[i * 2 + 1]; } vector<Node> data; int n, m; }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; using N0 = SegmentTree<less<>>::Node; using N1 = SegmentTree<greater<>>::Node; SegmentTree<less<>> st0(n * 2, N0{ 1 << 30, 0 }); SegmentTree<greater<>> st1(n * 2, N1{ 0, 0 }); vector<int64_t> sum(n + 1); vector<int> a(n); int64_t s0 = 0; for (int i = 0; i < n; i++) { int j = i + st0.m; cin >> st0.data[j].v; st0.data[j].i = i; s0 += st0.data[j].v; } st0.construct(); sum[0] = s0; for (int k = n; k < n * 2; k++) { cin >> a[k - n]; int64_t d = a[k - n] - st0.data[1].v; if (d > 0) { s0 += d; st0.update(st0.data[1].i, N0{ 1 << 30, 0 }); st0.update(k, N0{ a[k - n], k }); } sum[k - n + 1] = s0; } int64_t s1 = 0; for (int i = 0; i < n; i++) { int j = i + st0.m; cin >> st1.data[j].v; st1.data[j].i = i; s1 += st1.data[j].v; } st1.construct(); int64_t r = sum[n] - s1; for (int k = n * 2 - 1; k >= n; k--) { int64_t d = a[k - n] - st1.data[1].v; if (d < 0) { s1 += d; st1.update(st1.data[1].i, N1{ 0, 0 }); st1.update(k, N1{ a[k - n], k }); } r = max(r, sum[k - n] - s1); } cout << r << endl; return 0; }
a.cc: In function 'int main()': a.cc:51:36: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::less<void> >::Node&' to an rvalue of type 'N0' {aka 'SegmentTree<std::less<void> >::Node'} 51 | SegmentTree<less<>> st0(n * 2, N0{ 1 << 30, 0 }); | ^~~~~~~~~~~~~~~~ a.cc:22:30: note: initializing argument 2 of 'SegmentTree<C>::SegmentTree(int, Node&) [with C = std::less<void>]' 22 | SegmentTree(int n, Node& o) : n(n) { | ~~~~~~^ a.cc:52:39: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::greater<void> >::Node&' to an rvalue of type 'N1' {aka 'SegmentTree<std::greater<void> >::Node'} 52 | SegmentTree<greater<>> st1(n * 2, N1{ 0, 0 }); | ^~~~~~~~~~ a.cc:22:30: note: initializing argument 2 of 'SegmentTree<C>::SegmentTree(int, Node&) [with C = std::greater<void>]' 22 | SegmentTree(int n, Node& o) : n(n) { | ~~~~~~^ a.cc:71:39: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::less<void> >::Node&' to an rvalue of type 'N0' {aka 'SegmentTree<std::less<void> >::Node'} 71 | st0.update(st0.data[1].i, N0{ 1 << 30, 0 }); | ^~~~~~~~~~~~~~~~ a.cc:35:30: note: initializing argument 2 of 'void SegmentTree<C>::update(int, Node&) [with C = std::less<void>]' 35 | void update(int i, Node& o) { | ~~~~~~^ a.cc:72:27: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::less<void> >::Node&' to an rvalue of type 'N0' {aka 'SegmentTree<std::less<void> >::Node'} 72 | st0.update(k, N0{ a[k - n], k }); | ^~~~~~~~~~~~~~~~~ a.cc:35:30: note: initializing argument 2 of 'void SegmentTree<C>::update(int, Node&) [with C = std::less<void>]' 35 | void update(int i, Node& o) { | ~~~~~~^ a.cc:91:39: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::greater<void> >::Node&' to an rvalue of type 'N1' {aka 'SegmentTree<std::greater<void> >::Node'} 91 | st1.update(st1.data[1].i, N1{ 0, 0 }); | ^~~~~~~~~~ a.cc:35:30: note: initializing argument 2 of 'void SegmentTree<C>::update(int, Node&) [with C = std::greater<void>]' 35 | void update(int i, Node& o) { | ~~~~~~^ a.cc:92:27: error: cannot bind non-const lvalue reference of type 'SegmentTree<std::greater<void> >::Node&' to an rvalue of type 'N1' {aka 'SegmentTree<std::greater<void> >::Node'} 92 | st1.update(k, N1{ a[k - n], k }); | ^~~~~~~~~~~~~~~~~ a.cc:35:30: note: initializing argument 2 of 'void SegmentTree<C>::update(int, Node&) [with C = std::greater<void>]' 35 | void update(int i, Node& o) { | ~~~~~~^
s987820198
p03716
C++
#include <iostream> #include <sstream> #include <string> #include <cassert> #include <cmath> #include <climits> #include <cstdio> #include <vector> #include <map> #include <set> #include <queue> #include <deque> #include <algorithm> #include <functional> #include <numeric> #include <iomanip> using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; #define REP(i,n) for(int i = 0; i < (int)(n); ++i) #define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i) #define ALL(c) (c).begin(), (c).end() #define SIZE(v) ((int)v.size()) #define pb push_back #define mp make_pair #define mt make_tuple class FordFulkerson { private: // 陦後″蜈医€∝ョケ驥上€・€・セコ struct edge { int to, cap, rev; }; const int INF = 1e9; vector<vector<edge> > G; vector<char> used; public: FordFulkerson(int V){ G.resize(V); used.resize(V); } void add_uni_edge(int from, int to, int cap) { // rev縺ォ縺ッ縲・€・セコ縺ョ螳ケ驥上r縺吶$縺ォ蠕励k縺溘a縺ョ繧、繝ウ繝・ャ繧ッ繧ケ繧定ィ倬鹸 G[from].push_back( edge{ to, cap, SIZE(G[to])}); G[to].push_back( edge{from, 0, SIZE(G[from]) - 1}); } // 譛ェ繝・せ繝・ void add_bi_edge(int v1, int v2, int cap) { add_uni_edge(v1, v2, cap); add_uni_edge(v2, v1, cap); } // v縺九it縺セ縺ァ縺ョ譛€螟ァ豬√r霑斐☆ // f縺ッ縲・らせv縺ョ譎らせ縺ァ繧上°縺」縺ヲ縺・k蜿ッ閭ス縺ェ譛€螟ァ豬√・螟ァ縺阪&?? int dfs(int v, int t, int f) { if (v == t) return f; used[v] = true; // v逡ェ逶ョ縺ョ鬆らせ縺梧戟縺、霎コ縺ァ繝ォ繝シ繝・ REP(i, SIZE(G[v])){ edge &e = G[v][i]; // 縺セ縺霎コe縺ォ菴呵」輔′縺ゅk蝣エ蜷・ if (!used[e.to] && e.cap > 0) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(int s, int t) { int flow = 0; while (true) { fill(ALL(used), 0); int f = dfs(s, t, INF); if (f == 0) return flow; flow += f; } } void debug_print() { REP(from, SIZE(G)){ cout << "from " << from << ": " << endl; for (auto e : G[from]) { printf(" -> %d, capacity(%d), rev(%d)\n", e.to, e.cap, G[e.to][e.rev].cap); } cout << endl; } } }; int main(void) { cin.sync_with_stdio(false); int H, W; cin >> H >> W; vector<string> cells(H); pair<int,int> pos_s; pair<int,int> pos_t; REP(h, H) { cin >> cells[h]; REP(w, W) { if (cells[h][w] == 'S') { cells[h][w] = 'o'; pos_s = mp(h,w); } else if (cells[h][w] == 'T') { cells[h][w] = 'o'; pos_t = mp(h,w); } } } if (pos_s.first == pos_t.first || pos_s.second == pos_t.second) { cout << -1 << endl; return 0; } FordFulkerson ff(H + W + 2); REP(h, H) { REP(w, W) { if (cells[h][w] == 'o') { ff.add_bi_edge(h, H + w, 1); } } } ff.add_uni_edge(H + W, pos_s.first, 1e7); ff.add_uni_edge(H + W, H + pos_s.second, 1e7); ff.add_uni_edge(pos_t.first, H + W + 1, 1e7); ff.add_uni_edge(H + pos_t.second, H + W + 1, 1e7); auto flow = ff.max_flow(H + W, H + W + 1); cout << flow << endl; return 0; }
a.cc:55:22: error: 'v1' has not been declared 55 | add_uni_edge(v1, v2, cap); | ^~ a.cc:55:26: error: 'v2' has not been declared 55 | add_uni_edge(v1, v2, cap); | ^~ a.cc:55:30: error: 'cap' has not been declared 55 | add_uni_edge(v1, v2, cap); | ^~~ a.cc:55:9: error: ISO C++ forbids declaration of 'add_uni_edge' with no type [-fpermissive] 55 | add_uni_edge(v1, v2, cap); | ^~~~~~~~~~~~ a.cc:55:9: error: 'int FordFulkerson::add_uni_edge(int, int, int)' cannot be overloaded with 'void FordFulkerson::add_uni_edge(int, int, int)' a.cc:48:10: note: previous declaration 'void FordFulkerson::add_uni_edge(int, int, int)' 48 | void add_uni_edge(int from, int to, int cap) { | ^~~~~~~~~~~~ a.cc:56:22: error: 'v2' has not been declared 56 | add_uni_edge(v2, v1, cap); | ^~ a.cc:56:26: error: 'v1' has not been declared 56 | add_uni_edge(v2, v1, cap); | ^~ a.cc:56:30: error: 'cap' has not been declared 56 | add_uni_edge(v2, v1, cap); | ^~~ a.cc:56:9: error: ISO C++ forbids declaration of 'add_uni_edge' with no type [-fpermissive] 56 | add_uni_edge(v2, v1, cap); | ^~~~~~~~~~~~ a.cc:56:9: error: 'int FordFulkerson::add_uni_edge(int, int, int)' cannot be overloaded with 'void FordFulkerson::add_uni_edge(int, int, int)' a.cc:48:10: note: previous declaration 'void FordFulkerson::add_uni_edge(int, int, int)' 48 | void add_uni_edge(int from, int to, int cap) { | ^~~~~~~~~~~~ a.cc:57:6: error: expected ';' after class definition 57 | } | ^ | ; a.cc: In function 'int dfs(int, int, int)': a.cc:63:9: error: 'used' was not declared in this scope 63 | used[v] = true; | ^~~~ a.cc:66:13: error: 'edge' was not declared in this scope 66 | edge &e = G[v][i]; | ^~~~ a.cc:66:19: error: 'e' was not declared in this scope 66 | edge &e = G[v][i]; | ^ a.cc:66:23: error: 'G' was not declared in this scope 66 | edge &e = G[v][i]; | ^ a.cc:66:28: error: 'i' was not declared in this scope 66 | edge &e = G[v][i]; | ^ a.cc: At global scope: a.cc:75:9: error: expected declaration before '}' token 75 | } | ^ a.cc:76:9: error: expected unqualified-id before 'return' 76 | return 0; | ^~~~~~ a.cc:77:5: error: expected declaration before '}' token 77 | } | ^ a.cc: In function 'int max_flow(int, int)': a.cc:82:22: error: 'used' was not declared in this scope 82 | fill(ALL(used), 0); | ^~~~ a.cc:25:17: note: in definition of macro 'ALL' 25 | #define ALL(c) (c).begin(), (c).end() | ^ a.cc:83:31: error: 'INF' was not declared in this scope 83 | int f = dfs(s, t, INF); | ^~~ a.cc: In function 'void debug_print()': a.cc:90:24: error: 'G' was not declared in this scope 90 | REP(from, SIZE(G)){ | ^ a.cc:23:43: note: in definition of macro 'REP' 23 | #define REP(i,n) for(int i = 0; i < (int)(n); ++i) | ^ a.cc:90:19: note: in expansion of macro 'SIZE' 90 | REP(from, SIZE(G)){ | ^~~~ a.cc: At global scope: a.cc:99:1: error: expected declaration before '}' token 99 | }; | ^ a.cc: In function 'int main()': a.cc:133:20: error: 'class FordFulkerson' has no member named 'add_bi_edge'; did you mean 'add_uni_edge'? 133 | ff.add_bi_edge(h, H + w, 1); | ^~~~~~~~~~~ | add_uni_edge a.cc:141:20: error: 'class FordFulkerson' has no member named 'max_flow' 141 | auto flow = ff.max_flow(H + W, H + W + 1); | ^~~~~~~~ a.cc: In function 'int dfs(int, int, int)': a.cc:74:13: warning: control reaches end of non-void function [-Wreturn-type] 74 | } | ^
s577242362
p03716
C++
#import<bits/stdc++.h> using namespace std; typedef priority_queue<int> P; int i, N, a[300000]; long long d[100000], m; P q; main(){ cin >> N; for(; i < N * 3; ++i){ cin >> a[i]; q.push(-a[i]); m += a[i]; if(i ^ N - 1){ *d = m; } if(N <= i && i < N * 2){ m -= q.top(); q.pop(); d[i - N + 1] = m; } } q = P(); m = 0; for(i=N*3; --i+1;){ q.push(a[i]); m += a[i]; if(i == N * 2){ p[i - N] = m; } if((N <= i) && (i < N * 2)){ m += q.top(); q.pop(); p[i - N] = m; } } cout << *max_element(d, d + N + 1) << endl; }
a.cc:1:2: warning: #import is a deprecated GCC extension [-Wdeprecated] 1 | #import<bits/stdc++.h> | ^~~~~~ a.cc:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main(){ | ^~~~ a.cc: In function 'int main()': a.cc:29:13: error: 'p' was not declared in this scope 29 | p[i - N] = m; | ^ a.cc:34:13: error: 'p' was not declared in this scope 34 | p[i - N] = m; | ^
s195232737
p03716
C++
#include <iostream> #include <vector> #include <algorithm> #include <functional> #include <queue> #include <map> using namespace std; int main() { cout << nn << endl; long long int n; cin >> n; vector<long long int> a(3 * n); vector<long long int> b, c; priority_queue<long long int, vector<long long int>, greater<long long int> > pqb; long long int bb = 0; for (long long int i = 0; i < 3 * n; i++) { cin >> a[i]; if (i < n) { pqb.push(a[i]); bb += a[i]; } else { c.push_back(a[i]); } } sort(c.begin(), c.end()); long long int cc = 0; priority_queue<long long int, vector<long long int>, greater<long long int> > pqc; for (long long int i = 0; i < 2 * n; i++) { if (i < n) { cc += c[i]; } else { pqc.push(c[i]); } } long long int ans = bb - cc; map<long long int, long long int> mp; for (long long int i = n; i < 2 * n; i++) { if (a[i] > pqb.top()) { bb -= pqb.top(); pqb.pop(); bb += a[i]; pqb.push(a[i]); } if (a[i] <= pqc.top()) { cc -= a[i]; cc += pqc.top(); pqc.pop(); while (!pqc.empty()) { if (mp[pqc.top()] > 0) { mp[pqc.top()]--; pqc.pop(); } else { break; } } } else { mp[a[i]]++; } ans = max(ans, bb - cc); } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:11:17: error: 'nn' was not declared in this scope 11 | cout << nn << endl; | ^~
s416532020
p03716
C++
#include <climits> #include <cstring> #include <cmath> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <map> #include <set> #include <functional> #define fi first #define se second #define FO(x, n) for (int x = 0; x < n; ++x) #define FOR(x, a, b) for (int x = a; x < b; ++x) #define RFO(x, n) for (int x = n - 1; x >= 0; --x) #define RFOR(x, a, b) for (int x = b - 1; x >= a; --x) using namespace std; typedef unsigned char byte; typedef long long llong; typedef unsigned long long ullong; typedef pair<int, int> pii; typedef pair<double, double> pdd; typedef pair<string, string> pss; typedef pair<llong, llong> pll; inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; } int N; llong nums[100100]; llong l[100100]; llong r[100100]; int main() { while (cin >> N) { FO (i, N) cin >> nums[i]; priority_queue<llong, greater<llong> > ql; llong lsum = 0, rsum = 0; FO (i, N) lsum += nums[i]; l[0] = lsum; FO (i, N) { lsum += nums[N + i]; ql.push(nums[N + i]); llong pp = ql.top(); ql.pop(); lsum -= pp; l[i + 1] = lsum; } priority_queue<llong> qr; FO (i, N) rsum += nums[3 * N - 1 - i]; r[N] = rsum; FO (i, N) { rsum += nums[2 * N - 1 - i]; qr.push(nums[2 * N - 1 - i]); llong pp = qr.top(); rsum -= pp; r[N - 1 - i] = rsum; } llong res = INT_MIN; FO (i, N + 1) res = max(res, lsum[i] - rsum[i]); cout << res << endl; } return 0; }
a.cc: In function 'int main()': a.cc:39:46: error: no type named 'value_type' in 'struct std::greater<long long int>' 39 | priority_queue<llong, greater<llong> > ql; | ^ a.cc:39:46: error: template argument 3 is invalid a.cc:47:16: error: request for member 'push' in 'ql', which is of non-class type 'int' 47 | ql.push(nums[N + i]); | ^~~~ a.cc:48:27: error: request for member 'top' in 'ql', which is of non-class type 'int' 48 | llong pp = ql.top(); | ^~~ a.cc:49:16: error: request for member 'pop' in 'ql', which is of non-class type 'int' 49 | ql.pop(); | ^~~ a.cc:67:32: error: invalid types 'llong {aka long long int}[int]' for array subscript 67 | res = max(res, lsum[i] - rsum[i]); | ^ a.cc:67:42: error: invalid types 'llong {aka long long int}[int]' for array subscript 67 | res = max(res, lsum[i] - rsum[i]); | ^
s037682134
p03716
C++
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<n;++i) typedef long long ll; int main(void){ int N,res=0; cin>>N; vector<int> a(3*N); rep(i,3*N)cin>>a[i]; for(int M=N;M<2*N;M++){ priority_queue<int,vector<int>,greater<int>> lq; priority_queue<int> rq; rep(i,N){ if(i<M)lq.push(a[i]); else rq.push(a[i]); } while(lq.size()>N)lq.pop(); while(rq.size()>N)rq.pop(); ll suml=0,sumr=0; rep(i,N)suml+=lq.top(),lq.pop(); rep(i,N)sumr+=rq.top(),rq.pop(); res=max(res,suml-sumr); } cout<<res<<endl; return 0; }
a.cc: In function 'int main()': a.cc:23:24: error: no matching function for call to 'max(int&, ll)' 23 | res=max(res,suml-sumr); | ~~~^~~~~~~~~~~~~~~ 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: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: template argument deduction/substitution failed: a.cc:23:24: note: deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'}) 23 | res=max(res,suml-sumr); | ~~~^~~~~~~~~~~~~~~ /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, 2 provided In file included from /usr/include/c++/14/algorithm:61: /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: candidate expects 1 argument, 2 provided /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: template argument deduction/substitution failed: a.cc:23:24: note: mismatched types 'std::initializer_list<_Tp>' and 'int' 23 | res=max(res,suml-sumr); | ~~~^~~~~~~~~~~~~~~
s067314142
p03716
C++
#include<cstdio> #include<cstring> #include<vector> #include<queue> #include<algorithm> #include<cmath> #include<climits> #include<string> #include<set> #include<map> #include<iostream> using namespace std; #define rep(i,n) for(int i = 0;i<((int)(n));i++) #define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++) #define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--) #define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--) typedef long long int lli; typedef pair<lli, lli> mp; #define fir first #define sec second #define IINF INT_MAX #define LINF LLONG_MAX #define eprintf(...) fprintf(stderr,__VA_ARGS__) #define pque(type) priority_queue<type,vector<type>,greater<type> > #define memst(a,b) memset(a,b,sizeof(a)) struct SEGTREE{ vector<lli> v; int size; SEGTREE(vector<lli> a){ size = 1; while(1<<size < a.size()) size++; v.assign(1<<(size+1), LINF); rep(i, a.size()) v[(1<<size)+i] = a[i]; init(1); } lli init(int i){ if(i >= (1<<size)) return v[i]; else{ lli p1 = init(i*2); lli p2 = init(i*2+1); return v[i] = min(p1, p2); } } lli update(int r){ int rr = r + (1<<size); lli mi = v[rr]; while(true){ if(rr%2 == 1) rr /= 2; else rr = rr/2 - 1; mi = min(mi, v[rr]); if((rr&(rr-1)) == 0) break; } int pl = 1; while(true){ if(mi == v[pl*2]) pl = pl*2; else pl = pl*2 + 1; if(pl >= (1<<size)) break; } v[pl] = LINF; while(pl != 1){ pl/=2; v[pl] = min(v[pl*2], v[pl*2+1]); } return mi; } }; int main(void){ int n; cin >> n; vector<lli> t1(n*3), t2(n*3); rep(i, n*3){ cin >> t1[i]; t2[n*3-1-i] = -t1[i]; } SEGTREE st1(t1); SEGTREE st2(t2); vector<lli> s1(n+1), s2(n+1); s1[0] = accumulate(t1.begin(), t1.begin() + n, 0ll); rep(i, n) s1[i+1] = s1[i] - st1.update(n+i) + t1[n+i]; s2[0] = accumulate(t2.begin(), t2.begin() + n, 0ll); rep(i, n) s2[i+1] = s2[i] - st2.update(n+i) + t2[n+i]; reverse(s2.begin(), s2.end()); lli ans = -LINF; rep(i, n+1) ans = max(ans, s1[i] + s2[i]); cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:81:17: error: 'accumulate' was not declared in this scope 81 | s1[0] = accumulate(t1.begin(), t1.begin() + n, 0ll); | ^~~~~~~~~~
s885963073
p03716
C++
oo#include<bits/stdc++.h> using namespace std; typedef long long LL; #define CIN_ONLY if(1) struct cww{cww(){ CIN_ONLY{ ios::sync_with_stdio(false);cin.tie(0); } }}star; #define fin "\n" #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define DEBUG if(0) #define REC(ret, ...) std::function<ret (__VA_ARGS__)> template <typename T>inline bool chmin(T &l,T r) {bool a=l>r;if(a)l=r;return a;} template <typename T>inline bool chmax(T &l,T r) {bool a=l<r;if(a)l=r;return a;} template <typename T> istream& operator>>(istream &is,vector<T> &v){ for(auto &it:v)is>>it; return is; } vector<LL> solve(vector<LL> a){ priority_queue<LL,vector<LL>,greater<LL>> sub; priority_queue<LL> que; int N=a.size(); int m=N/3; vector<LL> res(m+1); REP(i,m)sub.push(a[i]); LL sum=0; FOR(i,m,2*m+1){ res[i-m]=sum; LL v=a[m]; que.push(v); sum+=v; v=que.top();que.pop(); sum-=v; sub.push(v); v=sub.top();sub.pop(); que.push(v); sum+=v; } return res; } int main(){ int m; cin>>m; int N=m*3; vector<LL> a(N); cin>>a; vector<LL> S(N+1,0); REP(i,N)S[i+1]=S[i]+a[i]; auto L=solve(a); reverse(ALL(a)); REP(i,N)a[i]*=-1; auto R=solve(a); reverse(ALL(a)); REP(i,N)a[i]*=-1; reverse(ALL(R)); for(auto &it:R)it*=-1; LL res=-1e17; REP(i,m+1){ //cout<<L[i]<<" "<<R[i]<<endl; LL lsum=S[i+m]-L[i]; LL rsum=S[N]-S[i+m]-R[i]; chmax(res,lsum-rsum); } cout<<res<<endl; return 0; }
a.cc:1:3: error: stray '#' in program 1 | oo#include<bits/stdc++.h> | ^ a.cc:1:1: error: 'oo' does not name a type; did you mean 'bool'? 1 | oo#include<bits/stdc++.h> | ^~ | bool a.cc: In constructor 'cww::cww()': a.cc:8:9: error: 'ios' has not been declared 8 | ios::sync_with_stdio(false);cin.tie(0); | ^~~ a.cc:8:37: error: 'cin' was not declared in this scope; did you mean 'fin'? 8 | ios::sync_with_stdio(false);cin.tie(0); | ^~~ | fin a.cc: At global scope: a.cc:25:1: error: 'istream' does not name a type 25 | istream& operator>>(istream &is,vector<T> &v){ | ^~~~~~~ a.cc:29:1: error: 'vector' does not name a type 29 | vector<LL> solve(vector<LL> a){ | ^~~~~~ a.cc: In function 'int main()': a.cc:53:5: error: 'cin' was not declared in this scope; did you mean 'fin'? 53 | cin>>m; | ^~~ | fin a.cc:55:5: error: 'vector' was not declared in this scope 55 | vector<LL> a(N); | ^~~~~~ a.cc:55:14: error: expected primary-expression before '>' token 55 | vector<LL> a(N); | ^ a.cc:55:16: error: 'a' was not declared in this scope 55 | vector<LL> a(N); | ^ a.cc:57:14: error: expected primary-expression before '>' token 57 | vector<LL> S(N+1,0); | ^ a.cc:57:16: error: 'S' was not declared in this scope 57 | vector<LL> S(N+1,0); | ^ a.cc:59:12: error: 'solve' was not declared in this scope 59 | auto L=solve(a); | ^~~~~ a.cc:60:5: error: 'reverse' was not declared in this scope 60 | reverse(ALL(a)); | ^~~~~~~ a.cc:74:5: error: 'cout' was not declared in this scope 74 | cout<<res<<endl; | ^~~~ a.cc:74:16: error: 'endl' was not declared in this scope 74 | cout<<res<<endl; | ^~~~
s485030440
p03716
C++
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> #include<bitset> #include<vector> #include<deque> #include<queue> #include<map> #include<set> #include<stack> #include<cmath> #include<iomanip> #include <functional> using namespace std; typedef long long ll; const int mod = 1000000007; const double EPS = 1e-10; //cout << fixed << std::setprecision(9) //memset(a, 0, sizeof(a)); //-------------------------- vector<ll> ab; int n; int main() { cin >> n; for (int i = 0;i < 3 * n;i++) { ll tmp; cin >> tmp; ab.push_back(tmp); } ll ans = -LONG_MAX; for (int i = 0;i <= n;i++) { vector<ll> a = ab; //for (int k = 0;k < 3 * n;k++) a[k] = ab[k]; sort(a.begin(), a.begin() + n + i); sort(a.begin()+ n + i, a.end()); ll l = 0; ll r = 0; for (int j = i;j < n + i;j++) l += a[j]; for (int j = n + i;j < 2 * n + i;j++) r += a[j]; //cout << i << ":" << l << "-" << r << endl; ans = max(ans, l - r); } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:36:19: error: 'LONG_MAX' was not declared in this scope 36 | ll ans = -LONG_MAX; | ^~~~~~~~ a.cc:16:1: note: 'LONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 15 | #include <functional> +++ |+#include <climits> 16 | using namespace std;
s045280715
p03716
C++
#include <iostream> #include <iomanip> #include <string> #include <vector> #include <queue> #include <algorithm> #include <utility> #include <cmath> #include <map> #include <set> #include <stack> #include <cstdio> #include <cstdlib> #include <cstring> using namespace std; #define INF_LL (ll)1e18 #define INF (int)1e9 #define REP(i, n) for(int i = 0;i < (n);i++) #define FOR(i, a, b) for(int i = (a);i < (b);i++) #define all(x) x.begin(),x.end() using ll = long long; using PII = pair<int, int>; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} class Union_find{ private: vector<int> par; vector<int> rank; int n; public: Union_find(int a){ n = a; for(int i = 0;i < n;i++){ par.push_back(i); rank.push_back(0); } } int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; if(rank[x] < rank[y]){ par[x] = y; }else{ par[y] = x; if(rank[x] == rank[y]) rank[x]++; } } bool same(int x, int y){ return find(x) == find(y); } }; class LazySegTree{ private: int n; vector<ll> node, lazy; vector<bool> lazyFlag; public: LazySegTree(vector<ll> v){ int sz = v.size(); n = 1; while(n < sz) n *= 2; node.resize(2*n-1, 0); lazy.resize(2*n-1, 0); lazyFlag.resize(2*n-1, false); REP(i, sz) node[i+n-1] = v[i]; for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2]; } void eval(int k, int l, int r){ if(lazyFlag[k]){ node[k] += lazy[k] * (r-l); if(r-l > 1){ lazy[2*k+1] += lazy[k]; lazy[2*k+2] += lazy[k]; lazyFlag[2*k+1] = lazyFlag[2*k+2] = true; } lazy[k] = 0; lazyFlag[k] = false; } } void add(int a, int b, ll x, int k=0, int l=0, int r=-1){ if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return; if(a <= l && r <= b){ lazy[k] += x; lazyFlag[k] = true; eval(k, l, r); }else{ add(a, b, x, k*2+1, l, (l+r)/2); add(a, b, x, k*2+2, (l+r)/2, r); node[k] = node[k*2+1] + node[k*2+2]; } } ll query(int a, int b, int k=0, int l=0, int r=-1){ if(r < 0) r = n; eval(k, l, r); if(b <= l || r <= a) return 0; if(a <= l && r <= b) return node[k]; return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r); } }; class Bucket{ private: int n, bs, bn; // 要素数、バケットサイズ、バケットの数 vector<ll> data; vector<ll> bucket, lazy; vector<bool> lazyFlag; public: Bucket(vector<ll> v, int sz){ data = v; n = v.size(); bs = sz; bn = (n + bs - 1) / bs; data.resize(bn*bs, INF_LL); bucket.assign(bn, INF_LL); lazy.assign(bn, 0); lazyFlag.assign(bn, 0); REP(i, bn){ ll minx = INF_LL; REP(j, bs){ chmin(minx, data[i*bs+j]); } bucket[i] = minx; } } void eval(int k){ if(lazyFlag[k]){ lazyFlag[k] = false; FOR(i, bs*k, bs*(k+1)){ data[i] = lazy[k]; } lazy[k] = 0; } } void update(int s, int t, int x){ REP(k, bn){ int l = k*bs, r = (k+1)*bs; if(r <= s || t <= l) continue; if(s <= l && r <= t){ lazyFlag[k] = true; bucket[k] = x; lazy[k] = x; }else{ eval(k); FOR(i, max(s, l), min(t, r)){ data[i] = x; } bucket[k] = INF_LL; FOR(i, l, r){ chmin(bucket[k], data[i]); } } } } ll query(int s, int t){ ll res = INF_LL; REP(k, bn){ int l = k*bs, r = (k+1)*bs; if(r <= s || t <= l) continue; if(s <= l && r <= t){ chmin(res, bucket[k]); }else{ eval(k); FOR(i, max(s, l), min(t, r)){ chmin(res, data[i]); } } } return res; } }; int main(void){ cin.tie(0); ios::sync_with_stdio(false); vector<ll> l, r; int N; cin >> N; if(N > 1000) return 0; ll a[114514]; l.push_back(0); REP(i, N){ ll b; cin >> b; l.push_back(b); } a[0] = 0; REP(i, N){ cin >> a[i+1]; a[i+1] += a[i]; } r.push_back(0); REP(i, N){ ll b; cin >> b; r.push_back(b); } sort(l.begin()+1, l.end(), greater<ll>()); sort(r.begin()+1, r.end();); REP(i, N){ l[i+1] += l[i]; r[i+1] += r[i]; } ll res = -INF_LL; REP(i, N+1){ REP(j, N-i+1){ res = max(res, l[N-i]+a[i]-(r[N-j]+a[N]-a[N-j])); } } cout << res << endl; }
a.cc: In function 'int main()': a.cc:222:34: error: expected ')' before ';' token 222 | sort(r.begin()+1, r.end();); | ~ ^ | ) a.cc:222:35: error: expected primary-expression before ')' token 222 | sort(r.begin()+1, r.end();); | ^
s744449676
p03716
C++
#include <iostream> using namespace std; pair<long long ,long long > arr[4001]; int main(){ int n; cin>>n; int t=3*n; for(int i=1;i<=t;i++){ cin>>arr[i].first; arr[i].second=i; } sort(arr+1,arr+t+1); long long ans=-2e18; for(int L=n;L<=2*n;L++){ long long mx=0; long long mn=0; long long mxcnt=0; long long mncnt=0; for(int j=t;j>=1;j--){ if(arr[j].second >= 1 && arr[j].second <= L && mxcnt!=n){ mxcnt++; mx+=arr[j].first; } } for(int j=1;j<=t;j++){ if(arr[j].second >= L+1 && arr[j].second<=t && mncnt!=n){ mncnt++; mn+=arr[j].first; } } ans=max(ans,mx-mn); } cout<<ans; return 0; }
a.cc: In function 'int main()': a.cc:11:5: error: 'sort' was not declared in this scope; did you mean 'short'? 11 | sort(arr+1,arr+t+1); | ^~~~ | short
s568402370
p03716
C++
a#include<bits/stdc++.h> #define F first #define S second #define pb push_back #define ll long long #define int long long #define ld double using namespace std ; const int MAXN = 101 * 1001 ; int a[MAXN] ; int32_t main() { ios::sync_with_stdio(0) ; cin.tie(0) ; int n ; cin >> n ; n *= 3 ; for(int i = 0 ; i < n ; i ++ ) cin >> a[i] ; int ans = -1e18 ; multiset<int> s1 , s2 , s3 ; int m = n / 3 ; int sum1 = 0 , sum2 = 0 ; for(int i = 0 ; i < n ; i ++ ) s2.insert(a[i]) , sum2 += a[i] ; while(s2.size()>m) { sum2 -= *s2.rbegin() ; s3.insert(*s2.rbegin()) ; s2.erase(s2.find(*s2.rbegin())) ; } for(int i = 0 ; i < 2 * m ; i ++ ) { s1.insert(a[i]) ; sum1 += a[i] ; // cout <<'*'<< sum1 << ' ' << i << endl ; if(s3.find(a[i])!=s3.end()) s3.erase(s3.find(a[i])) ; else s2.erase(s2.find(a[i])) , sum2 -= a[i] ; while(s1.size()>m) { sum1 -= *s1.begin() ; s1.erase(s1.find(*s1.begin())) ; } // cout << sum1<< endl ; while(s2.size()<m) { sum2 += *s3.begin() ; s2.insert(*s3.begin()) ; s3.erase(s3.find(*s3.begin())) ; } if(s1.size()>=m) { // cout << sum2 << ' ' << sum1 << endl ; ans = max(ans,sum1-sum2) ; } } cout << ans << endl ; }
a.cc:1:2: error: stray '#' in program 1 | a#include<bits/stdc++.h> | ^ a.cc:1:1: error: 'a' does not name a type 1 | a#include<bits/stdc++.h> | ^ a.cc:16:1: error: 'int32_t' does not name a type 16 | int32_t main() | ^~~~~~~ a.cc:1:1: note: 'int32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>' +++ |+#include <cstdint> 1 | a#include<bits/stdc++.h>
s267750630
p03717
C++
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <set> #include <map> #include <queue> #include <random> #include <chrono> #include <tuple> #include <random> using namespace std; typedef long long ll; typedef long double ld; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10, MOD = 1e9 + 7; //insane bug ll dp[303][8]; struct ev { ll l, r, k; }; vector<vector<ev>> scan; vector<vector<ll>> er; vector<ll> c = { 0, 1, 1, 2, 1, 2, 2, 3 }; int main() { fastInp; ll n, m; cin >> n >> m; scan.resize(n); er.resize(n); for (int i = 0; i < m; i++) { ll l, r, k; cin >> l >> r >> k; l--; r--; scan[l].push_back({ l, r, k }); er[r].push_back(k); } dp[0][0] = 1; ll pr = 3; multiset<ll> s; //s.insert(3); for (int i = 0; i < n; i++) { for (auto cur : scan[i]) { s.insert(cur.k); } ll cur = *(s.begin()); if (cur >= pr) { for (int j = 0; j < 8; j++) { for (int t = 0; t <= 2; t++) { ll bt = (1ll << t); dp[i + 1][bt] += dp[i][j]; } } } else if (cur < pr) { for (int j = 0; j < 8; j++) { for (int k = 0; k < 8; k++) { for (int t = 0; t <= 2; t++) { ll bt = (1ll << t); if ((j | k) == j && (k | bt) == k) { dp[i + 1][(j | bt)] += dp[i][j]; } } } } } for (int j = 0; j < 8; j++) { if (c[j] > cur) { dp[i + 1][j] = 0; } } for (int j = 0; j < 8; j++) dp[i][j] %= MOD; pr = *(s.begin()); for (auto cur : er[i]) { for (int j = 0; j < 8; j++) { if (cnt[j] != cur) dp[i + 1][j] = 0; } s.erase(s.find(cur)); } } ll sm = 0; for (int i = 0; i < 8; i++) sm += dp[n][i]; cout << sm; return 0; }
a.cc: In function 'int main()': a.cc:91:37: error: 'cnt' was not declared in this scope; did you mean 'int'? 91 | if (cnt[j] != cur) dp[i + 1][j] = 0; | ^~~ | int
s243123630
p03717
C++
#include <iostream> #include <algorithm> #include <utility> #include <vector> #include <numeric> template <uint32_t Modulus> class modular { public: using value_type = uint32_t; using max_type = uint64_t; static constexpr value_type mod = Modulus; static constexpr value_type mod_min = 1; static constexpr value_type mod_max = 2147483647; static_assert(mod >= mod_min, "invalid mod :: too small"); static_assert(mod <= mod_max, "invalid mod :: too big"); template <class T> static constexpr value_type normalize(T value_) { if (value_ < 0) { value_ = -value_; value_ %= mod; if (value_ == 0) return 0; return mod - value_; } return value_ % mod; } private: value_type value; public: constexpr modular(): value(0) { } template <class T> explicit constexpr modular(T value_): value(normalize(value_)) { } template <class T> explicit constexpr operator T() { return static_cast<T>(value); } constexpr value_type operator () () const { return value; } constexpr modular operator - () const { return modular(mod - value); } constexpr modular operator ~ () const { return inverse(); } constexpr value_type &extract() { return value; } constexpr modular inverse() const { return power(mod - 2); } constexpr modular power(max_type exp) const { modular res(1), mult(*this); while (exp > 0) { if (exp & 1) res *= mult; mult *= mult; exp >>= 1; } return res; } constexpr modular operator + (const modular &rhs) const { return modular(*this) += rhs; } constexpr modular& operator += (const modular &rhs) { if ((value += rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator - (const modular &rhs) const { return modular(*this) -= rhs; } constexpr modular& operator -= (const modular &rhs) { if ((value += mod - rhs.value) >= mod) value -= mod; return *this; } constexpr modular operator * (const modular &rhs) const { return modular(*this) *= rhs; } constexpr modular& operator *= (const modular &rhs) { value = (max_type) value * rhs.value % mod; return *this; } constexpr modular operator / (const modular &rhs) const { return modular(*this) /= rhs; } constexpr modular& operator /= (const modular &rhs) { return (*this) *= rhs.inverse(); } constexpr bool zero() const { return value == 0; } constexpr bool operator == (const modular &rhs) const { return value == rhs.value; } constexpr bool operator != (const modular &rhs) const { return value != rhs.value; } friend std::ostream& operator << (std::ostream &stream, const modular &rhs) { return stream << rhs.value; } }; using modint = modular<1000000007>; template <class T, std::size_t N, std::size_t I = 0> decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I == N), const T&>::type value = T()) { return value; } template <class T, std::size_t N, std::size_t I = 0> decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T()) { return std::vector(list[I], gen_vec<T, N, I + 1>(list, value)); } int main() { int N, M; std::cin >> N >> M; auto query = gen_vec<std::pair<int, int>>({ N + 1, 0 }); for (int i = 0; i < M; ++i) { int l, r, x; std::cin >> l >> r >> x; query[r].emplace_back(l, x); } auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 }); dp[0][0][0] = modint(1); for (int r = 0; r < N; ++r) { for (int g = 0; g < N; ++g) { for (int b = 0; b < N; ++b) { int i = std::max({ r, g, b }) + 1; for (int next: { 0, 1, 2 }) { int idx[] = { r, g, b }; idx[next] = i; if ([&] { for (auto p: query[i]) { int cnt = 0; for (int k: { 0, 1, 2 }) { if (idx[k] >= p.first) { ++cnt; } } if (cnt != p.second) { return false; } } return true; }()) { dp[idx[0]][idx[1]][idx[2]] += dp[r][g][b]; } } } } } modint ans; for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { ans += dp[N][i][j]; ans += dp[i][N][j]; ans += dp[i][j][N]; } } std::cout << ans << '\n'; return 0; }
a.cc:8:11: error: 'uint32_t' has not been declared 8 | template <uint32_t Modulus> | ^~~~~~~~ a.cc:11:22: error: 'uint32_t' does not name a type 11 | using value_type = uint32_t; | ^~~~~~~~ a.cc:7:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>' 6 | #include <numeric> +++ |+#include <cstdint> 7 | a.cc:12:20: error: 'uint64_t' does not name a type 12 | using max_type = uint64_t; | ^~~~~~~~ a.cc:12:20: note: 'uint64_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>' a.cc:14:20: error: 'value_type' does not name a type 14 | static constexpr value_type mod = Modulus; | ^~~~~~~~~~ a.cc:15:20: error: 'value_type' does not name a type 15 | static constexpr value_type mod_min = 1; | ^~~~~~~~~~ a.cc:16:20: error: 'value_type' does not name a type 16 | static constexpr value_type mod_max = 2147483647; | ^~~~~~~~~~ a.cc:17:17: error: 'mod' was not declared in this scope 17 | static_assert(mod >= mod_min, "invalid mod :: too small"); | ^~~ a.cc:17:24: error: 'mod_min' was not declared in this scope 17 | static_assert(mod >= mod_min, "invalid mod :: too small"); | ^~~~~~~ a.cc:18:17: error: 'mod' was not declared in this scope 18 | static_assert(mod <= mod_max, "invalid mod :: too big"); | ^~~ a.cc:18:24: error: 'mod_max' was not declared in this scope 18 | static_assert(mod <= mod_max, "invalid mod :: too big"); | ^~~~~~~ a.cc:21:20: error: 'value_type' does not name a type 21 | static constexpr value_type normalize(T value_) { | ^~~~~~~~~~ a.cc:32:3: error: 'value_type' does not name a type 32 | value_type value; | ^~~~~~~~~~ a.cc:41:13: error: 'value_type' does not name a type 41 | constexpr value_type operator () () const { return value; } | ^~~~~~~~~~ a.cc:45:13: error: 'value_type' does not name a type 45 | constexpr value_type &extract() { return value; } | ^~~~~~~~~~ a.cc:47:27: error: 'max_type' has not been declared 47 | constexpr modular power(max_type exp) const { | ^~~~~~~~ a.cc: In function 'int main()': a.cc:102:49: warning: narrowing conversion of '(N + 1)' from 'int' to 'std::size_t' {aka 'long unsigned int'} [-Wnarrowing] 102 | auto query = gen_vec<std::pair<int, int>>({ N + 1, 0 }); | ~~^~~ a.cc:108:21: error: 'modint' was not declared in this scope; did you mean 'mode_t'? 108 | auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 }); | ^~~~~~ | mode_t a.cc:108:28: error: no matching function for call to 'gen_vec<<expression error> >(<brace-enclosed initializer list>)' 108 | auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 }); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:90:16: note: candidate: 'template<class T, long unsigned int N, long unsigned int I> decltype(auto) gen_vec(const std::size_t (&)[N], typename std::enable_if<(I == N), const T&>::type)' 90 | decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I == N), const T&>::type value = T()) { | ^~~~~~~ a.cc:90:16: note: template argument deduction/substitution failed: a.cc:108:28: error: template argument 1 is invalid 108 | auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 }); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:95:16: note: candidate: 'template<class T, long unsigned int N, long unsigned int I> decltype(auto) gen_vec(const std::size_t (&)[N], typename std::enable_if<(I != N), const T&>::type)' 95 | decltype(auto) gen_vec(const std::size_t (&list)[N], typename std::enable_if<(I != N), const T&>::type value = T()) { | ^~~~~~~ a.cc:95:16: note: template argument deduction/substitution failed: a.cc:108:28: error: template argument 1 is invalid 108 | auto dp = gen_vec<modint>({ N + 1, N + 1, N + 1 }); | ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:137:9: error: expected ';' before 'ans' 137 | modint ans; | ^~~~ | ; a.cc:140:7: error: 'ans' was not declared in this scope; did you mean 'abs'? 140 | ans += dp[N][i][j]; | ^~~ | abs a.cc:145:16: error: 'ans' was not declared in this scope; did you mean 'abs'? 145 | std::cout << ans << '\n'; | ^~~ | abs
s396155584
p03717
C++
#include <iostream> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<P, int> PP; const ll MOD = 1000000007; ll dp[2][304][304]; int main() { int n, m; cin >> n >> m; PP p[304]; for(int i = 0; i < m; i++){ int l, r, x; cin >> l >> r >> x; p[i] = PP(P(r, l), x); } sort(p, p + m); int l = 0; dp[0][0][0] = 1; for(int i = 1; i <= n; i++){ for(int j = 0; j < i; j++){ for(int k = 0; k < j; k++){ dp[i % 2][j][k] = dp[(i + 1) % 2][j][k]; } } for(int j_ = 0; j_ < i; j_++){ for(int k = 0; k < j_; k++){ dp[i % 2][i - 1][k] = (dp[i % 2][i - 1][k] + dp[(i + 1) % 2][j_][k]) % MOD; } } for(int k = 0; k < i; k++){ for(int k_ = 0; k_ < k; k_++){ dp[i % 2][i - 1][k] = (dp[i % 2][i - 1][k] + dp[(i + 1) % 2][k][k_]) % MOD; } } if(i != 1){ dp[i % 2][i - 1][0] = (dp[i % 2][i - 1][0] + dp[(i + 1) % 2][0][0] * 2) % MOD; dp[i % 2][0][0] = dp[(i + 1) % 2][0][0]; } else dp[i][0][0] = 3; while(p[l].first.first == i){ if(p[l].second == 1){ for(int j = 0; j <= i; j++){ for(int k = 0; k <= j; k++){ if(j >= p[l].first.second) dp[i % 2][j][k] = 0; } } } else if(p[l].second == 2){ for(int j = 0; j <= i; j++){ for(int k = 0; k <= j; k++){ if(j < p[l].first.second || k >= p[l].first.second) dp[i % 2][j][k] = 0; } } } else{ for(int j = 0; j <= i; j++){ for(int k = 0; k <= j; k++){ if(k < p[l].first.second){ dp[i % 2][j][k] = 0; } } } } l++; } } ll ans = 0; for(int j = 0; j < n; j++){ for(int k = 0; k < j; k++) ans = (ans + dp[n % 2][j][k]) % MOD; } cout << ans << endl; }
a.cc: In function 'int main()': a.cc:21:5: error: 'sort' was not declared in this scope; did you mean 'short'? 21 | sort(p, p + m); | ^~~~ | short
s482686385
p03717
Java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.NoSuchElementException; import java.util.function.IntBinaryOperator; import java.util.function.UnaryOperator; import lib.MathUtil; public class Main { public static void main(String[] args) { Out out = new Out(); solve(out); out.outln(); out.flush(); out.close(); } public static void solve(Out out) { int mod = (int) Const.MOD7; int n = Math.max(3, In.ni()); int m = In.ni(); int[] rlx = new int[m]; int b1 = MathUtil.ceilExponent(n + 1); int b2 = b1 << 1; int mask1 = (1 << b1) - 1; int mask2 = (1 << b2) - 1; int l, r, x; for (int i = 0; i < m; i++) { l = In.ni(); r = In.ni(); x = In.ni(); rlx[i] = (r << b2) + (l << b1) + x; } Arrays.sort(rlx); int[] ft = ArrayUtil.filledArray(-1, n + 1); int bm = MathUtil.ceilExponent(m); int mask = (1 << bm) - 1; for (int i = 0; i < m; i++) { l = (rlx[i] & mask2) >> b1; r = rlx[i] >> b2; x = rlx[i] & mask1; if (i == 0 || r != rlx[i - 1] >> b2) { ft[r] = 0; ft[r] += i; } if (i == m - 1 || r != rlx[i + 1] >> b2) { ft[r] += i << bm; } } int n2 = (n + 1) * (n + 1); int n1 = n + 1; int[] dp = new int[n1 * n1 * n1]; dp[0] = 1; int i, j, k; int p, q; int fr, to; int ii, jj, kk; int ijk, ijk2; boolean ok, ib, jb, kb, and, xor; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { for (k = 0; k < n; k++) { ijk = i * n2 + j * n1 + k; if (dp[ijk] == 0) { continue; } r = IntUtil.max(i, j, k); for (q = 0; q < 3; q++) { ii = q == 0 ? r + 1 : i; jj = q == 1 ? r + 1 : j; kk = q == 2 ? r + 1 : k; ijk2 = ii * n2 + jj * n1 + kk; if ((ii == jj & ii != 0) | (jj == kk & jj != 0) | (kk == ii & kk != 0)) { continue; } if (ft[r + 1] < 0) { dp[ijk2] += dp[ijk]; if (dp[ijk2] >= mod) { dp[ijk2] -= mod; } } else { ok = true; fr = ft[r + 1] & mask; to = ft[r + 1] >> bm; for (p = fr; p <= to; p++) { l = (rlx[p] & mask2) >> b1; x = rlx[p] & mask1; ib = ii >= l; jb = jj >= l; kb = kk >= l; and = ib & jb & kb; xor = ib ^ jb ^ kb; ok &= (x == 1 & !and & xor) | (x == 2 & !xor) | (x == 3 & and); if (!ok) { break; } } if (ok) { dp[ijk2] += dp[ijk]; if (dp[ijk2] >= mod) { dp[ijk2] -= mod; } } } } } } } long ans = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { ans += dp[n * n2 + i * n1 + j]; ans += dp[j * n2 + n * n1 + i]; ans += dp[i * n2 + j * n1 + n]; } } out.append(ans % mod); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } } class IntUtil { private IntUtil(){} public static int min(int... a) { int ret = Const.IINF; for (int c : a) ret = Math.min(ret, c); return ret; } public static int max(int... a) { int ret = -Const.IINF; for (int c : a) ret = Math.max(ret, c); return ret; } /** * Caluculate the ceil of a/b. Returns the smallest integer greater than or * equal to a/b while 'a/b' rounds fractional parts to ZERO. * * @param a * @param b * @return the smallest integer greater than or equal to a/b */ public static int cld(int a, int b) { if (a > 0 && b > 0) return (a + b - 1) / b; else if (a < 0 && b < 0) return (a + b + 1) / b; else return a / b; } /** * Caluculate the floor of a/b. Returns the largest integer less than or equal * to a/b while 'a/b' rounds fractional parts to ZERO. * * @param a * @param b * @return the largest integer less than or equal to a/b */ public static int fld(int a, int b) { if (a <= 0 && b > 0) return (a - b + 1) / b; else if (a > 0 && b <= 0) return (a - b - 1) / b; else return a / b; } public static int fold(IntBinaryOperator func, int e, int... a) { int ret = e; for (int c : a) ret = func.applyAsInt(ret, c); return ret; } } class Out { private StringBuilder sb = new StringBuilder(); private PrintWriter w = new PrintWriter(System.out); public Out() { } public void append(int v) { sb.append(v); } public void append(long v) { sb.append(v); } public void append(char c) { sb.append(c); } public void append(double v) { sb.append(v); } public void append(char[] c) { sb.append(c); } public void append(String s) { sb.append(s); } public void append(Object e) { sb.append(e); } public void append(int[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(long[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(char[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(double[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(char[][] c, String sep) { for (int i = 0; i < c.length; i++) { append(c[i]); if (i < c.length - 1) { append(sep); } } } public void append(String[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(Object[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void out() { w.print(sb); clearBuilder(); } public void outln() { w.println(sb); clearBuilder(); } public void print(int v) { w.print(v); } public void print(long v) { w.print(v); } public void print(char c) { w.print(c); } public void print(double v) { w.print(v); } public void print(String s) { w.print(s); } public void print(Object e) { w.print(e); } public void print(String sep, int... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, long... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, char... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, double... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, String... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, Object... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void println() { w.println(); } public void println(int v) { w.println(v); } public void println(long v) { w.println(v); } public void println(double v) { w.println(v); } public void println(char c) { w.println(c); } public void println(String s) { w.println(s); } public void println(Object e) { w.println(e); } public void println(String sep, int... a) { print(sep, a); println(); } public void println(String sep, long... a) { print(sep, a); println(); } public void println(String sep, double... a) { print(sep, a); println(); } public void println(String sep, char... a) { print(sep, a); println(); } public void println(String sep, String... a) { print(sep, a); println(); } // public void println(String sep, Object... a) { // print(sep, a); // println(); // } public void flush() { w.flush(); } public void close() { w.close(); } public void clearBuilder() { sb = new StringBuilder(); } public void reverse() { sb.reverse(); } public void delete(int start, int end) { sb.delete(start, end); } public void delete(int length) { sb.delete(sb.length() - length, sb.length()); } public int length() { return sb.length(); } } class Const { public static final long MOD7 = 1_000_000_007; public static final long MOD9 = 1_000_000_009; public static final long MOD99 = 998_244_353; public static final long LINF = 1_000_000_000_000_000_000l; public static final int IINF = 1_000_000_000; public static final double DINF = 1e150; public static final double DELTA = 0.000_000_000_1; public static final double LDELTA = 0.000_001; public static final String YES = "YES"; public static final String NO = "NO"; public static final String Yes = "Yes"; public static final String No = "No"; public static final String POSSIBLE = "POSSIBLE"; public static final String IMPOSSIBLE = "IMPOSSIBLE"; public static final String Possible = "Possible"; public static final String Impossible = "Impossible"; public static final int[] dx8 = {1, 0, -1, 0, 1, -1, -1, 1}; public static final int[] dy8 = {0, 1, 0, -1, 1, 1, -1, -1}; public static final int[] dx = {1, 0, -1, 0}; public static final int[] dy = {0, 1, 0, -1}; private Const(){} } class In { public static final FastScanner fsc = new FastScanner(); public static int ni() { return fsc.nextInt(); } public static int[] ni(int n) { int[] a = new int[n]; Arrays.setAll(a, i -> fsc.nextInt()); return a; } public static int[][] ni(int n, int m) { int[][] a = new int[n][m]; Arrays.setAll(a, i -> ni(m)); return a; } public static long nl() { return fsc.nextLong(); } public static long[] nl(int n) { long[] a = new long[n]; Arrays.setAll(a, i -> fsc.nextLong()); return a; } public static long[][] nl(int n, int m) { long[][] a = new long[n][m]; Arrays.setAll(a, i -> nl(m)); return a; } public static char[] nc() { return fsc.next().toCharArray(); } public static char[][] nc(int n, int m) { char[][] c = new char[n][m]; Arrays.setAll(c, i -> nc()); return c; } public static double nd() { return fsc.nextDouble(); } public static double[] nd(int n) { double[] a = new double[n]; Arrays.setAll(a, i -> nd()); return a; } public static double[][] nd(int n, int m) { double[][] a = new double[n][m]; Arrays.setAll(a, i -> nd(m)); return a; } public static String ns() { return fsc.next(); } public static String[] ns(int n) { String[] s = new String[n]; Arrays.setAll(s, i -> ns()); return s; } public static boolean[][] inputGrid(int h, int w, char truechar) { boolean[][] grid = new boolean[h][w]; for (int i = 0; i < h; i++) { char[] s = fsc.next().toCharArray(); for (int j = 0; j < w; j++) { grid[i][j] = s[j] == truechar; } } return grid; } } class ArrayUtil { public static int[] compress(long[] a) { int n = a.length; HashSet<Long> set = new HashSet<>(); for (long e : a) { set.add(e); } ArrayList<Long> sorted = new ArrayList<>(set); int size = sorted.size(); Collections.sort(sorted); int[] compress = new int[n]; for (int i = 0; i < n; i++) { int l = 0, r = size; while (r - l > 1) { int m = l + (r - l) / 2; if (sorted.get(m) <= a[i]) { l = m; } else { r = m; } } compress[i] = l + 1; } return compress; } /** * destructive methods */ public static void swap(int[] a, int u, int v) { int tmp = a[u]; a[u] = a[v]; a[v] = tmp; } public static void swap(long[] a, int u, int v) { long tmp = a[u]; a[u] = a[v]; a[v] = tmp; } public static void reverse(int[] a, int begin, int end) { for (int i = begin; i < begin + (end - begin) / 2; i++) { swap(a, i, begin + end - i - 1); } } public static void reverse(int[] a) { reverse(a, 0, a.length); } public static void reverse(long[] a, int begin, int end) { for (int i = begin; i < begin + (end - begin) / 2; i++) { swap(a, i, begin + end - i - 1); } } public static void reverse(long[] a) { reverse(a, 0, a.length); } public static void revSort(int[] a) { Arrays.sort(a); reverse(a); } public static void revSort(long[] a) { Arrays.sort(a); reverse(a); } public static void sort(int[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> u[sortIndex] - v[sortIndex]); } public static void sort(int[][] a) { sort(a, 0); } public static void sort(long[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> Long.compare(u[sortIndex], v[sortIndex])); } public static void sort(long[][] a) { sort(a, 0); } public static void revSort(int[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> v[sortIndex] - u[sortIndex]); } public static void revSort(int[][] a) { revSort(a, 0); } public static void revSort(long[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> Long.compare(v[sortIndex], u[sortIndex])); } public static void revSort(long[][] a) { revSort(a, 0); } /** * permutation */ public static int[] nextPermutation(int[] a) { int[] ret = a.clone(); int n = ret.length; for (int i = n - 1; i >= 1; i--) { if (ret[i] > ret[i - 1]) { int fail = n, pass = i; while (fail - pass > 1) { int mid = pass + (fail - pass) / 2; if (ret[mid] > ret[i - 1]) { pass = mid; } else { fail = mid; } } swap(ret, pass, i - 1); reverse(ret, i, n); return ret; } } return null; } public static int[] predPermutation(int[] a) { int[] ret = a.clone(); int n = ret.length; for (int i = n - 1; i >= 1; i--) { if (ret[i] < ret[i - 1]) { int fail = n, pass = i; while (fail - pass > 1) { int mid = pass + (fail - pass) / 2; if (ret[mid] < ret[i - 1]) { pass = mid; } else { fail = mid; } } swap(ret, pass, i - 1); reverse(ret, i, n); return ret; } } return null; } /** * */ public static int[] map(UnaryOperator<Integer> op, int[] a) { int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static long[] map(UnaryOperator<Long> op, long[] a) { long[] b = new long[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static <T> T[] map(UnaryOperator<T> op, T[] a) { @SuppressWarnings("unchecked") T[] b = (T[]) new Object[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static int[][] transpose(int[][] a) { int n = a.length; int m = a[0].length; int[][] ret = new int[m][n]; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { ret[j][i] = a[i][j]; } } return ret; } public static long[][] transpose(long[][] a) { int n = a.length; int m = a[0].length; long[][] ret = new long[m][n]; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { ret[j][i] = a[i][j]; } } return ret; } /** * comparation */ public static int compare(int[] a, int[] b) { for (int i = 0; i < a.length; i++) { if (i >= b.length) { return -1; } else if (a[i] > b[i]) { return 1; } else if (a[i] < b[i]) { return -1; } } if (a.length < b.length) { return 1; } else { return 0; } } public static int compare(long[] a, long[] b) { for (int i = 0; i < a.length; i++) { if (i >= b.length) { return -1; } else if (a[i] > b[i]) { return 1; } else if (a[i] < b[i]) { return -1; } } if (a.length < b.length) { return 1; } else { return 0; } } public static boolean equals(int[] a, int[] b) { return compare(a, b) == 0; } public static boolean equals(long[] a, long[] b) { return compare(a, b) == 0; } /** * initialize methods */ public static int[] filledArray(int init, int n) { int[] ret = new int[n]; Arrays.fill(ret, init); return ret; } public static int[][] filledArray(int init, int n, int m) { int[][] ret = new int[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(ret[i], init); } return ret; } public static long[] filledArray(long init, int n) { long[] ret = new long[n]; Arrays.fill(ret, init); return ret; } public static long[][] filledArray(long init, int n, int m) { long[][] ret = new long[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(ret[i], init); } return ret; } }
Main.java:12: error: package lib does not exist import lib.MathUtil; ^ Main.java:28: error: cannot find symbol int b1 = MathUtil.ceilExponent(n + 1); ^ symbol: variable MathUtil location: class Main Main.java:41: error: cannot find symbol int bm = MathUtil.ceilExponent(m); ^ symbol: variable MathUtil location: class Main 3 errors
s555963385
p03717
Java
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.NoSuchElementException; import java.util.function.IntBinaryOperator; import java.util.function.UnaryOperator; public class Main { public static void main(String[] args) { Out out = new Out(); solve(out); out.outln(); out.flush(); out.close(); } public static void solve(Out out) { ModuloArithmetic ma = new ModuloArithmetic(Const.MOD7); int n = In.ni(); int m = In.ni(); int[][] lrx = new int[m][3]; for (int i = 0; i < m; i++) { lrx[i][0] = In.ni(); lrx[i][1] = In.ni(); lrx[i][2] = In.ni() } ArrayUtil.sort(lrx, 1); int[] fr = ArrayUtil.filledArray(-1, n + 1); int[] to = ArrayUtil.filledArray(-2, n + 1); for (int i = 0; i < m; i++) { if (i == 0 || lrx[i][1] != lrx[i - 1][1]) { fr[lrx[i][1]] = i; } if (i == m - 1 || lrx[i][1] != lrx[i + 1][1]) { to[lrx[i][1]] = i; } } long[] dp = new long[(n + 1) * (n + 1) *(n + 1)]; int n2 = (n + 1) * (n + 1); int n1 = n + 1; dp[0] = 1; int i, j, k; int p, q; int ii, jj, kk; int ijk, ijk2; int l, r, x; boolean ok, ib, jb, kb, and, xor; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { for (k = 0; k < n; k++) { ijk = i * n2 + j * n1 + k; if (dp[ijk] == 0) { continue; } r = IntUtil.max(i, j, k); for (q = 0; q < 3; q++) { ii = q == 0 ? r + 1 : i; jj = q == 1 ? r + 1 : j; kk = q == 2 ? r + 1 : k; ijk2 = ii * n2 + jj * n1 + kk; if ((ii == jj & ii != 0) | (jj == kk & jj != 0) | (kk == ii & kk != 0)) { continue; } if (fr[r + 1] < 0) { dp[ijk2] = ma.add(dp[ijk2], dp[ijk]); } else { ok = true; for (p = fr[r + 1]; p <= to[r + 1]; p++) { l = lrx[p][0]; x = lrx[p][2]; ib = ii >= l; jb = jj >= l; kb = kk >= l; and = ib & jb & kb; xor = ib ^ jb ^ kb; ok &= (x == 1 & !and & xor) | (x == 2 & !xor) | (x == 3 & and); } if (ok) { dp[ijk2] = ma.add(dp[ijk2], dp[ijk]); } } } } } } long ans = 0; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { ans += dp[n * n2 + i * n1 + j]; ans += dp[j * n2 + n * n1 + i]; ans += dp[i * n2 + j * n1 + n]; } } out.append(ma.mod(ans)); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) { return buffer[ptr++]; } else { return -1; } } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) { ptr++; } return hasNextByte(); } public String next() { if (!hasNext()) { throw new NoSuchElementException(); } StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) { throw new NoSuchElementException(); } long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) { throw new NumberFormatException(); } return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } } class IntUtil { private IntUtil(){} public static int min(int... a) { int ret = Const.IINF; for (int c : a) ret = Math.min(ret, c); return ret; } public static int max(int... a) { int ret = -Const.IINF; for (int c : a) ret = Math.max(ret, c); return ret; } /** * Caluculate the ceil of a/b. Returns the smallest integer greater than or * equal to a/b while 'a/b' rounds fractional parts to ZERO. * * @param a * @param b * @return the smallest integer greater than or equal to a/b */ public static int cld(int a, int b) { if (a > 0 && b > 0) return (a + b - 1) / b; else if (a < 0 && b < 0) return (a + b + 1) / b; else return a / b; } /** * Caluculate the floor of a/b. Returns the largest integer less than or equal * to a/b while 'a/b' rounds fractional parts to ZERO. * * @param a * @param b * @return the largest integer less than or equal to a/b */ public static int fld(int a, int b) { if (a <= 0 && b > 0) return (a - b + 1) / b; else if (a > 0 && b <= 0) return (a - b - 1) / b; else return a / b; } public static int fold(IntBinaryOperator func, int e, int... a) { int ret = e; for (int c : a) ret = func.applyAsInt(ret, c); return ret; } } class ModuloArithmetic { private final long MOD; private long[] fact; private long[] pow; /** * support modulo p arithmetic * * @param p p s.t. p is a prime number. */ public ModuloArithmetic(long p) { this.MOD = p; } /** * Calculate x s.t. 0 <= x < MOD /\ x = a mod p. * * @param a * @return x s.t. 0 <= x < MOD /\ x = a mod p. */ public long mod(long a) { a %= MOD; return a < 0 ? a + MOD : a; } /** * Calculate x s.t. 0 <= x < MOD /\ x = a_1 + 1_2 + ... + a_k mod p. * * @param a * @return x s.t. 0 <= x < MOD /\ x = a_1 + 1_2 + ... + a_k mod p. */ public long sum(long... a) { long ret = 0; for (long c : a) ret += c; return mod(ret); } /** * Calculate x s.t. 0 <= x < MOD /\ x = a + b mod p. * * @param a * @param b * @return x s.t. 0 <= x < MOD /\ x = a + b mod p. */ public long add(long a, long b) { long s = a + b; return s < 0 ? s + MOD : s >= MOD ? s - MOD : s; } /** * Calculate x s.t. 0 <= x < MOD /\ x = a - b mod p. * * @param a * @param b * @return x s.t. 0 <= x < MOD /\ x = a - b mod p. */ public long sub(long a, long b) { long s = a - b; return s < 0 ? s + MOD : s >= MOD ? s - MOD : s; } /** * Calculate x s.t. 0 <= x < MOD /\ x = a_1 * 1_2 * ... * a_k mod p. * * @param a * @return x s.t. 0 <= x < MOD /\ x = a_1 * 1_2 * ... * a_k mod p. */ public long prod(long... a) { long ret = 1; for (long c : a) { ret = (ret * c) % MOD; } return ret < 0 ? ret + MOD : ret; } /** * Calculate x s.t. 0 <= x < MOD /\ x = a * b mod p. * * @param a * @param b * @return x s.t. 0 <= x < MOD /\ x = a * b mod p. */ public long mul(long a, long b) { return mod(a * b); } /** * Calculate x s.t. 0 <= x < MOD /\ b * x = a mod p. * * @param a * @param b * @return x s.t. 0 <= x < MOD /\ b * x = a mod p. */ public long div(long a, long b) { return mul(a, inv(b)); } /** * Calculate the value b s.t. a*b mod MOD = 1. * * @param a * @return inverse of a */ public long inv(long a) { long b = MOD; long u = 1, v = 0; while (b >= 1) { long t = a / b; a -= t * b; long tmp1 = a; a = b; b = tmp1; u -= t * v; long tmp2 = u; u = v; v = tmp2; } return mod(u); } /** * Calculate the permutation nPr. * * @param n * @param r * @return nPr */ public long perm(long n, long r) { if (n < r) { return 0; } if (fact != null && n <= fact.length) { return div(fact[(int) n], fact[(int) (n - r)]); } long ret = 1; for (long i = n; i > n - r; i--) { ret = mul(ret, i); } return ret; } /** * Calculate the combination nCr. * * @param n * @param r * @return nCr */ public long comb(long n, long r) { if (n < r) { return 0; } if (fact != null && n <= fact.length) { return div(fact[(int) n], mul(fact[(int) (n - r)], fact[(int) r])); } r = Math.min(r, n - r); long res = 1; for (long d = 1; d <= r; d++) { res = div(mul(res, n--), d); } return res; } /** * call this method after building factorial array. * * @param n * @return n! mod p */ public long fact(int n) { return fact[n]; } /** * call this nethod after building power array. * * @param n * @return (base)^n */ public long pow(int n) { return pow[n]; } /** * Calculate a^b (mod {@code MOD}) in O(log b) time. * * @param a base * @param b index * @return a^b (mod {@code MOD}) */ public long pow(long a, long b) { if (b == 0) { return 1; } long half = pow(a, b >> 1); if ((a & 1) == 0) { return mul(half, half); } else { return prod(half, half, a); } } /** * build factorial array from 0 to n (closed) * * @param n */ public void buildFactorial(int n) { this.fact = new long[n + 1]; for (int i = 0; i <= n; i++) { if (i <= 1) { fact[i] = 1; } else { fact[i] = mul(fact[i - 1], i); } } } /** * build power array based on a from 0 to n (closed) * * @param a base of power * @param n */ public void buildPower(long a, int n) { if (a == 2) { buildPower(n); } else { this.pow = new long[n + 1]; for (int i = 0; i <= n; i++) { if (i == 0) { pow[i] = 1; } else { pow[i] = mul(pow[i - 1], a); } } } } /** * build power array based on 2 from 0 to n (closed) * * @param n */ public void buildPower(int n) { this.pow = new long[n + 1]; for (int i = 0; i <= n; i++) { if (i == 0) { pow[i] = 1; } else { pow[i] = pow[i - 1] << 1; if (pow[i] >= MOD) { pow[i] -= MOD; } } } } } class Out { private StringBuilder sb = new StringBuilder(); private PrintWriter w = new PrintWriter(System.out); public Out() { } public void append(int v) { sb.append(v); } public void append(long v) { sb.append(v); } public void append(char c) { sb.append(c); } public void append(double v) { sb.append(v); } public void append(char[] c) { sb.append(c); } public void append(String s) { sb.append(s); } public void append(Object e) { sb.append(e); } public void append(int[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(long[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(char[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(double[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(char[][] c, String sep) { for (int i = 0; i < c.length; i++) { append(c[i]); if (i < c.length - 1) { append(sep); } } } public void append(String[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void append(Object[] a, String sep) { for (int i = 0; i < a.length; i++) { append(a[i]); if (i < a.length - 1) { append(sep); } } } public void out() { w.print(sb); clearBuilder(); } public void outln() { w.println(sb); clearBuilder(); } public void print(int v) { w.print(v); } public void print(long v) { w.print(v); } public void print(char c) { w.print(c); } public void print(double v) { w.print(v); } public void print(String s) { w.print(s); } public void print(Object e) { w.print(e); } public void print(String sep, int... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, long... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, char... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, double... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, String... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void print(String sep, Object... a) { StringBuilder s = new StringBuilder(); for (int i = 0; i < a.length; i++) { s.append(a[i]); if (i < a.length - 1) { s.append(sep); } } print(s); } public void println() { w.println(); } public void println(int v) { w.println(v); } public void println(long v) { w.println(v); } public void println(double v) { w.println(v); } public void println(char c) { w.println(c); } public void println(String s) { w.println(s); } public void println(Object e) { w.println(e); } public void println(String sep, int... a) { print(sep, a); println(); } public void println(String sep, long... a) { print(sep, a); println(); } public void println(String sep, double... a) { print(sep, a); println(); } public void println(String sep, char... a) { print(sep, a); println(); } public void println(String sep, String... a) { print(sep, a); println(); } // public void println(String sep, Object... a) { // print(sep, a); // println(); // } public void flush() { w.flush(); } public void close() { w.close(); } public void clearBuilder() { sb = new StringBuilder(); } public void reverse() { sb.reverse(); } public void delete(int start, int end) { sb.delete(start, end); } public void delete(int length) { sb.delete(sb.length() - length, sb.length()); } public int length() { return sb.length(); } } class Const { public static final long MOD7 = 1_000_000_007; public static final long MOD9 = 1_000_000_009; public static final long MOD99 = 998_244_353; public static final long LINF = 1_000_000_000_000_000_000l; public static final int IINF = 1_000_000_000; public static final double DINF = 1e150; public static final double DELTA = 0.000_000_000_1; public static final double LDELTA = 0.000_001; public static final String YES = "YES"; public static final String NO = "NO"; public static final String Yes = "Yes"; public static final String No = "No"; public static final String POSSIBLE = "POSSIBLE"; public static final String IMPOSSIBLE = "IMPOSSIBLE"; public static final String Possible = "Possible"; public static final String Impossible = "Impossible"; public static final int[] dx8 = {1, 0, -1, 0, 1, -1, -1, 1}; public static final int[] dy8 = {0, 1, 0, -1, 1, 1, -1, -1}; public static final int[] dx = {1, 0, -1, 0}; public static final int[] dy = {0, 1, 0, -1}; private Const(){} } class In { public static final FastScanner fsc = new FastScanner(); public static int ni() { return fsc.nextInt(); } public static int[] ni(int n) { int[] a = new int[n]; Arrays.setAll(a, i -> fsc.nextInt()); return a; } public static int[][] ni(int n, int m) { int[][] a = new int[n][m]; Arrays.setAll(a, i -> ni(m)); return a; } public static long nl() { return fsc.nextLong(); } public static long[] nl(int n) { long[] a = new long[n]; Arrays.setAll(a, i -> fsc.nextLong()); return a; } public static long[][] nl(int n, int m) { long[][] a = new long[n][m]; Arrays.setAll(a, i -> nl(m)); return a; } public static char[] nc() { return fsc.next().toCharArray(); } public static char[][] nc(int n, int m) { char[][] c = new char[n][m]; Arrays.setAll(c, i -> nc()); return c; } public static double nd() { return fsc.nextDouble(); } public static double[] nd(int n) { double[] a = new double[n]; Arrays.setAll(a, i -> nd()); return a; } public static double[][] nd(int n, int m) { double[][] a = new double[n][m]; Arrays.setAll(a, i -> nd(m)); return a; } public static String ns() { return fsc.next(); } public static String[] ns(int n) { String[] s = new String[n]; Arrays.setAll(s, i -> ns()); return s; } public static boolean[][] inputGrid(int h, int w, char truechar) { boolean[][] grid = new boolean[h][w]; for (int i = 0; i < h; i++) { char[] s = fsc.next().toCharArray(); for (int j = 0; j < w; j++) { grid[i][j] = s[j] == truechar; } } return grid; } } class ArrayUtil { public static int[] compress(long[] a) { int n = a.length; HashSet<Long> set = new HashSet<>(); for (long e : a) { set.add(e); } ArrayList<Long> sorted = new ArrayList<>(set); int size = sorted.size(); Collections.sort(sorted); int[] compress = new int[n]; for (int i = 0; i < n; i++) { int l = 0, r = size; while (r - l > 1) { int m = l + (r - l) / 2; if (sorted.get(m) <= a[i]) { l = m; } else { r = m; } } compress[i] = l + 1; } return compress; } /** * destructive methods */ public static void swap(int[] a, int u, int v) { int tmp = a[u]; a[u] = a[v]; a[v] = tmp; } public static void swap(long[] a, int u, int v) { long tmp = a[u]; a[u] = a[v]; a[v] = tmp; } public static void reverse(int[] a, int begin, int end) { for (int i = begin; i < begin + (end - begin) / 2; i++) { swap(a, i, begin + end - i - 1); } } public static void reverse(int[] a) { reverse(a, 0, a.length); } public static void reverse(long[] a, int begin, int end) { for (int i = begin; i < begin + (end - begin) / 2; i++) { swap(a, i, begin + end - i - 1); } } public static void reverse(long[] a) { reverse(a, 0, a.length); } public static void revSort(int[] a) { Arrays.sort(a); reverse(a); } public static void revSort(long[] a) { Arrays.sort(a); reverse(a); } public static void sort(int[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> u[sortIndex] - v[sortIndex]); } public static void sort(int[][] a) { sort(a, 0); } public static void sort(long[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> Long.compare(u[sortIndex], v[sortIndex])); } public static void sort(long[][] a) { sort(a, 0); } public static void revSort(int[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> v[sortIndex] - u[sortIndex]); } public static void revSort(int[][] a) { revSort(a, 0); } public static void revSort(long[][] a, int sortIndex) { Arrays.sort(a, (u, v) -> Long.compare(v[sortIndex], u[sortIndex])); } public static void revSort(long[][] a) { revSort(a, 0); } /** * permutation */ public static int[] nextPermutation(int[] a) { int[] ret = a.clone(); int n = ret.length; for (int i = n - 1; i >= 1; i--) { if (ret[i] > ret[i - 1]) { int fail = n, pass = i; while (fail - pass > 1) { int mid = pass + (fail - pass) / 2; if (ret[mid] > ret[i - 1]) { pass = mid; } else { fail = mid; } } swap(ret, pass, i - 1); reverse(ret, i, n); return ret; } } return null; } public static int[] predPermutation(int[] a) { int[] ret = a.clone(); int n = ret.length; for (int i = n - 1; i >= 1; i--) { if (ret[i] < ret[i - 1]) { int fail = n, pass = i; while (fail - pass > 1) { int mid = pass + (fail - pass) / 2; if (ret[mid] < ret[i - 1]) { pass = mid; } else { fail = mid; } } swap(ret, pass, i - 1); reverse(ret, i, n); return ret; } } return null; } /** * */ public static int[] map(UnaryOperator<Integer> op, int[] a) { int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static long[] map(UnaryOperator<Long> op, long[] a) { long[] b = new long[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static <T> T[] map(UnaryOperator<T> op, T[] a) { @SuppressWarnings("unchecked") T[] b = (T[]) new Object[a.length]; for (int i = 0; i < a.length; i++) { b[i] = op.apply(a[i]); } return b; } public static int[][] transpose(int[][] a) { int n = a.length; int m = a[0].length; int[][] ret = new int[m][n]; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { ret[j][i] = a[i][j]; } } return ret; } public static long[][] transpose(long[][] a) { int n = a.length; int m = a[0].length; long[][] ret = new long[m][n]; for (int j = 0; j < m; j++) { for (int i = 0; i < n; i++) { ret[j][i] = a[i][j]; } } return ret; } /** * comparation */ public static int compare(int[] a, int[] b) { for (int i = 0; i < a.length; i++) { if (i >= b.length) { return -1; } else if (a[i] > b[i]) { return 1; } else if (a[i] < b[i]) { return -1; } } if (a.length < b.length) { return 1; } else { return 0; } } public static int compare(long[] a, long[] b) { for (int i = 0; i < a.length; i++) { if (i >= b.length) { return -1; } else if (a[i] > b[i]) { return 1; } else if (a[i] < b[i]) { return -1; } } if (a.length < b.length) { return 1; } else { return 0; } } public static boolean equals(int[] a, int[] b) { return compare(a, b) == 0; } public static boolean equals(long[] a, long[] b) { return compare(a, b) == 0; } /** * initialize methods */ public static int[] filledArray(int init, int n) { int[] ret = new int[n]; Arrays.fill(ret, init); return ret; } public static int[][] filledArray(int init, int n, int m) { int[][] ret = new int[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(ret[i], init); } return ret; } public static long[] filledArray(long init, int n) { long[] ret = new long[n]; Arrays.fill(ret, init); return ret; } public static long[][] filledArray(long init, int n, int m) { long[][] ret = new long[n][m]; for (int i = 0; i < n; i++) { Arrays.fill(ret[i], init); } return ret; } }
Main.java:29: error: ';' expected lrx[i][2] = In.ni() ^ 1 error
s207924973
p03717
C++
#include<bits/stdc++.h> #define ll long long using namespace std; struct aaa{ int x,y,w; }a[1010]; const int p=1e9+7; vector<int>zh[1010]; int n,m,i,j,x,sz,k,l,ans,f[302][302][302]; int main(){ scanf("%d%d",&n,&m); for(i=1;i<=m;i++){ scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w); zh[a[i].y].push_back(i); } f[1][0][0]=3; for(i=1;i<=n;i++){ for(j=1;j<i;j++) for(k=0;k<j;k++){ for(l=0;l<zh[i].size();l++){ x=zh[i][l]; sz=1; if(a[x].x<=j)sz++; if(a[x].x<=k)sz++; if(sz!=a[x].w)f[i][j][k]=0; } if(!f[i][j][k])continue; (f[i+1][j][k]+=f[i][j][k])%=p; (f[i+1][i][k]+=f[i][j][k])%=p; (f[i+1][i][j]+=f[i][j][k])%=p; } for(l=0;l<zh[i].size();l++){ x=zh[i][l]; if(a[x].w!=1)f[i][0][0]=0; } (f[i+1][0][0]+=f[i][0][0])%=p; (f[i+1][i][0]+=f[i][0][0]*2%p)%=p; } for(j=0;j<n;j++) for(k=0;k<=j;k++)ans=(ans+f[n][j][k])%=p; printf("%d",ans); }
a.cc: In function 'int main()': a.cc:40:29: error: lvalue required as left operand of assignment 40 | for(k=0;k<=j;k++)ans=(ans+f[n][j][k])%=p; | ~~~~^~~~~~~~~~~~
s944550335
p03717
C++
LGY Will F**k The All Universe
a.cc:1:1: error: 'LGY' does not name a type 1 | LGY Will F**k The All Universe | ^~~
s181034478
p03717
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; typedef vector<pi> vpi; typedef double dl; #define mp make_pair #define pb emplace_back #define f first #define s second #define MOD 1e9+7 #define lb lower_bound #define ub upper_bound #define dst distance #define INF 1000000000 #define ALL(x) x.begin(), x.end() #define SZ(x) (int)x.size() #define MAXN 310 ll MOD = 1e9+7; int N,M,a,b,c; vpi V[MAXN]; int dp[MAXN][MAXN][MAXN]; int ask(int n, int a, int b){ if (dp[n][a][b] != -1)return dp[n][a][b]; if (n == N){ // cout<<"1 way "<<n<<' '<<a<<' '<<b<<'\n'; // Exactly 1 way return dp[n][a][b] = 1; } if(a!=b)return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a) + ask(n+1,n,b))%MOD; else return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a))%MOD; } int main(){ cin>>N>>M; int samework = 1; for (int i=0;i<M;++i){ cin>>a>>b>>c; if (c>1)samework = 0; V[b].pb(a,c); } memset(dp,-1,sizeof(dp)); for (int b=0;b<=N;++b){ for (int a=b;a<=N;++a){ for (int i=a+1;i<=N;++i){ for (auto v:V[i]){ int has_b = (b >= v.f); int has_a = (a>=v.f); int t = has_a+has_b+1; if (t != v.s){dp[i][a][b] = 0;break;} } } } } int ans = ask(1,0,0)*6%MOD; if (samework)ans = (ans-3+MOD)%MOD; cout<<ans; // for (int i=0;i<=N;++i){ // for (int j=0;j<=N;++j){ // for (int k=0;k<=N;++k)cout<<dp[i][j][k]<<' ';cout<<'\n'; // } // cout<<'\n'; // } }
a.cc:12:13: error: expected unqualified-id before numeric constant 12 | #define MOD 1e9+7 | ^~~ a.cc:20:4: note: in expansion of macro 'MOD' 20 | ll MOD = 1e9+7; | ^~~ a.cc: In function 'int ask(int, int, int)': a.cc:33:82: error: invalid operands of types 'int' and 'double' to binary 'operator%' 33 | if(a!=b)return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a) + ask(n+1,n,b))%MOD; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ | | | int a.cc:34:64: error: invalid operands of types 'int' and 'double' to binary 'operator%' 34 | else return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a))%MOD; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ | | | int a.cc: In function 'int main()': a.cc:58:31: error: invalid operands of types 'int' and 'double' to binary 'operator%' 58 | int ans = ask(1,0,0)*6%MOD; | ~~~~~~~~~~~~^ | | | int a.cc:59:39: error: invalid operands of types 'double' and 'double' to binary 'operator%' 59 | if (samework)ans = (ans-3+MOD)%MOD; | ~~~~~~~~~~~^
s933240863
p03717
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll,ll> pi; typedef vector<pi> vpi; typedef double dl; #define mp make_pair #define pb emplace_back #define f first #define s second #define MOD 1e9+7 #define lb lower_bound #define ub upper_bound #define dst distance #define INF 1000000000 #define ALL(x) x.begin(), x.end() #define SZ(x) (int)x.size() #define MAXN 310 int N,M,a,b,c; vpi V[MAXN]; int dp[MAXN][MAXN][MAXN]; int ask(int n, int a, int b){ if (dp[n][a][b] != -1)return dp[n][a][b]; if (n == N){ // cout<<"1 way "<<n<<' '<<a<<' '<<b<<'\n'; // Exactly 1 way return dp[n][a][b] = 1; } if(a!=b)return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a) + ask(n+1,n,b))%MOD; else return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a))%MOD; } int main(){ cin>>N>>M; int samework = 1; for (int i=0;i<M;++i){ cin>>a>>b>>c; if (c>1)samework = 0; V[b].pb(a,c); } memset(dp,-1,sizeof(dp)); for (int b=0;b<=N;++b){ for (int a=b;a<=N;++a){ for (int i=a+1;i<=N;++i){ for (auto v:V[i]){ int has_b = (b >= v.f); int has_a = (a>=v.f); int t = has_a+has_b+1; if (t != v.s){dp[i][a][b] = 0;break;} } } } } int ans = ask(1,0,0)*6%MOD; if (samework)ans = (ans-3+MOD)%MOD; cout<<ans; // for (int i=0;i<=N;++i){ // for (int j=0;j<=N;++j){ // for (int k=0;k<=N;++k)cout<<dp[i][j][k]<<' ';cout<<'\n'; // } // cout<<'\n'; // } }
a.cc: In function 'int ask(int, int, int)': a.cc:32:82: error: invalid operands of types 'int' and 'double' to binary 'operator%' 32 | if(a!=b)return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a) + ask(n+1,n,b))%MOD; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ | | | int a.cc:33:64: error: invalid operands of types 'int' and 'double' to binary 'operator%' 33 | else return dp[n][a][b] = (ask(n+1,a,b) + ask(n+1,n,a))%MOD; | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ | | | int a.cc: In function 'int main()': a.cc:57:31: error: invalid operands of types 'int' and 'double' to binary 'operator%' 57 | int ans = ask(1,0,0)*6%MOD; | ~~~~~~~~~~~~^ | | | int a.cc:58:39: error: invalid operands of types 'double' and 'double' to binary 'operator%' 58 | if (samework)ans = (ans-3+MOD)%MOD; | ~~~~~~~~~~~^
s413420128
p03717
C++
dp[r][ma+1][b] += dp[r][g][b]; dp[r][g][ma+1] += dp[r][g][b]; dp[ma+1][g][b] %= mod; dp[r][ma+1][b] %= mod; dp[r][g][ma+1] %= mod; } } } ll ans = 0; for (int r = 0; r <= N; r++) { for (int g = 0; g <= N; g++) { for (int b = 0; b <= N; b++) { if (max(max(r, g), b) == N) { ans += dp[r][g][b]; } ans %= mod; } } } puts(ans); return 0; }
a.cc:1:33: error: 'dp' does not name a type 1 | dp[r][ma+1][b] += dp[r][g][b]; | ^~ a.cc:2:33: error: 'dp' does not name a type 2 | dp[r][g][ma+1] += dp[r][g][b]; | ^~ a.cc:3:33: error: 'dp' does not name a type 3 | dp[ma+1][g][b] %= mod; | ^~ a.cc:4:33: error: 'dp' does not name a type 4 | dp[r][ma+1][b] %= mod; | ^~ a.cc:5:33: error: 'dp' does not name a type 5 | dp[r][g][ma+1] %= mod; | ^~ a.cc:6:25: error: expected declaration before '}' token 6 | } | ^ a.cc:7:17: error: expected declaration before '}' token 7 | } | ^ a.cc:8:9: error: expected declaration before '}' token 8 | } | ^ a.cc:11:9: error: 'll' does not name a type 11 | ll ans = 0; | ^~ a.cc:12:9: error: expected unqualified-id before 'for' 12 | for (int r = 0; r <= N; r++) { | ^~~ a.cc:12:25: error: 'r' does not name a type 12 | for (int r = 0; r <= N; r++) { | ^ a.cc:12:33: error: 'r' does not name a type 12 | for (int r = 0; r <= N; r++) { | ^ a.cc:22:13: error: expected constructor, destructor, or type conversion before '(' token 22 | puts(ans); | ^ a.cc:24:9: error: expected unqualified-id before 'return' 24 | return 0; | ^~~~~~ a.cc:25:1: error: expected declaration before '}' token 25 | } | ^
s553425963
p03717
C++
#include <bits/stdc++.h> using namespace std; #define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--) #define forsn(i,s,n) for(int i=int(s);i<int(n);i++) #define dforn(i,n) dforsn(i,0,n) #define forn(i,n) forsn(i,0,n) #define all(a) a.begin(),a.end() #define si(a) int((a).size()) #define pb emplace_back #define mp make_pair #define snd second #define fst first #define endl '\n' using pii = pair<int,int>; using vi = vector<int>; using ll = long long; using vii = vector<pii>; const int N = 300+1, M = 1e9+7, C = 3; int n, m, memo[N][N][N]; vii conditions[N]; int add(int a, int b) { return a + b >= M ? a + b - M : a + b; } bool valid(int pos, int last0, int last1, int last2) { for (auto lx : conditions[pos]) { int l, x; tie(l, x) = lx; int cant = (last0 >= l) + (last1 >= l) + (last2 >= l); if (cant != x) return false; } return true; } int dp(int last0 = 0, int last1 = 0, int last2 = 0) { int pos = max({last0, last1, last2})+1; if (pos == n+1) return 1; int &res = memo[last0][last1][last2]; if (res != -1) return res; res = 0; if (valid(pos, pos, last1, last2)) res = add(res, dp(pos, last1, last2)); if (valid(pos, last0, pos, last2)) res = add(res, dp(last0, pos, last2)); if (valid(pos, last0, last1, pos)) res = add(res, dp(last0, last1, pos)); return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0) cin >> n >> m; while (m--) { int l, r, x; cin >> l >> r >> x; conditions[r].pb(l, x); } fill(memo[0][0], memo[N][0], -1); cout << dp() << endl; }
a.cc: In function 'int main()': a.cc:58:41: error: expected ';' before 'cin' 58 | ios_base::sync_with_stdio(0); cin.tie(0) | ^ | ; 59 | 60 | cin >> n >> m; | ~~~
s373987843
p03717
C
#include <iostream> #include <vector> #include <cstdio> #include <cstring> using namespace std; typedef long long intl; struct query{ int ini,fin,X; void Leer() { scanf("%d %d %d",&ini,&fin,&X); } }; bool Cumple(query q, int r, int g, int b) { int x = 0; if(q.ini<=r && r<=q.fin) x++; if(q.ini<=b && b<=q.fin) x++; if(q.ini<=g && g<=q.fin) x++; return x == q.X; } intl MOD = 1e9 + 7; intl DP[320][320][320]; /// r g b vector<query> Q[320]; int main() { memset(DP,0,sizeof(DP)); int N,M; cin>>N>>M; for(int i = 0;i<M;i++) { query q; q.Leer(); Q[q.fin].push_back(q); } DP[1][0][0] = 1; DP[0][1][0] = 1; DP[0][0][1] = 1; intl R = 0; for(int i = 1;i<=N;i++) { for(int g = 0;g<i;g++) for(int b = 0;b<i;b++) { if(b!=g || b == 0 || g == 0) { for(auto q : Q[i]) if(!Cumple(q,i,g,b)) DP[i][g][b] = 0; // cout<<i<<" - "<<g<<" - "<<g<<" : "<<DP[i][g][b]<<endl; DP[i+1][g][b] = (DP[i+1][g][b] + DP[i][g][b])%MOD; DP[i][i+1][b] = (DP[i][i+1][b] + DP[i][g][b])%MOD; DP[i][g][i+1] = (DP[i][g][i+1] + DP[i][g][b])%MOD; if(i == N) R = (R+DP[i][g][b])%MOD; } } for(int r = 0;r<i;r++) for(int b = 0;b<i;b++) { if(b!=r || r == 0 || b == 0) { for(auto q : Q[i]) if(!Cumple(q,r,i,b)) DP[r][i][b] = 0; DP[i+1][i][b] = (DP[i+1][i][b] + DP[r][i][b])%MOD; DP[r][i+1][b] = (DP[r][i+1][b] + DP[r][i][b])%MOD; DP[r][i][i+1] = (DP[r][i][i+1] + DP[r][i][b])%MOD; if(i == N) R = (R+DP[r][i][b])%MOD; } } for(int r = 0;r<i;r++) for(int g = 0;g<i;g++) { if(g!=r || r == 0 || g == 0) { for(auto q : Q[i]) if(!Cumple(q,r,g,i)) DP[r][g][i] = 0; DP[i+1][g][i] = (DP[i+1][g][i] + DP[r][g][i])%MOD; DP[r][i+1][i] = (DP[r][i+1][i] + DP[r][g][i])%MOD; DP[r][g][i+1] = (DP[r][g][i+1] + DP[r][g][i])%MOD; if(i == N) R = (R+DP[r][g][i])%MOD; } } } cout<<R<<endl; }
main.c:1:10: fatal error: iostream: No such file or directory 1 | #include <iostream> | ^~~~~~~~~~ compilation terminated.
s953893788
p03717
C++
#include<cstring> #include<algorithm> #include<vector> #define mod 1000000007 using namespace std; int dp[310][310][310]; bool visited[310][310][310]; int n, m; int ma(int x, int y, int z) { return max(max(x, y), z); } int func(int x, int y, int z) { int &ret = dp[x][y][z]; if (ret != -1)return ret; if (ma(x, y, z) == n)return 1; ret = 0; int ch = ma(x, y, z); ret += func(ch+1, y, z); ret %= mod; ret += func(x, ch+1, z); ret %= mod; ret += func(x, y, ch+1); ret %= mod; return ret; } int main() { memset(dp, -1, sizeof(dp)); scanf("%d %d", &n, &m); while(m--){ int q, w, e; scanf("%d %d %d", &q, &w, &e); if (e == 1) { for (int i = 0; i <= w; i++) { for (int y = 0; y <= w; y++) { if (i < q&&y < q)continue; dp[w][i][y] = 0; dp[i][w][y] = 0; dp[i][y][w] = 0; } } } else if (e==2) { for(int i = 0; i <= w; i++) { for (int y = 0; y <= w; y++) { if ((i >= q && y < q) || (i < q&&y >= q))continue; dp[w][i][y] = 0; dp[y][w][i] = 0; dp[y][i][w] = 0; } } } else { for (int i = 0; i <=w; i++) { for (int y = 0; y <= w; y++) { if (i >= q && y >= q)continue; dp[w][i][y] = 0; dp[i][w][y] = 0; dp[i][y][w] = 0; } } } } printf("%d\n", func(0, 0, 0)); }
a.cc: In function 'int main()': a.cc:29:9: error: 'scanf' was not declared in this scope 29 | scanf("%d %d", &n, &m); | ^~~~~ a.cc:65:9: error: 'printf' was not declared in this scope 65 | printf("%d\n", func(0, 0, 0)); | ^~~~~~ a.cc:4:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' 3 | #include<vector> +++ |+#include <cstdio> 4 | #define mod 1000000007
s233560903
p03717
C++
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define INF (1<<30) #define INFLL (1ll<<60) typedef pair<int, int> P; typedef pair<int, P> E; #define MOD (1000000007) #define l_ength size void mul_mod(int& a, int b){ a *= b; a %= MOD; } void add_mod(int& a, int b){ b += MOD; a += b; a %= MOD; } struct edge{ int l, x; }; vector<edge> g[334]; int dp[334][334][334]; int main(void){ int n,m,i,j,k,t,l,r,x; ll ans=0; edge e; cin >> n >> m; for(t=0; t<m; ++t){ cin >> l >> r >> x; e.l = l; e.x = x; g[r].push_back(e); } dp[0][0][0] = 1; for(i=0; i<=n; ++i){ for(j=0; j<=n; ++j){ for(k=0; k<=n; ++k){ r = max(i,max(j,k)); l = min(i,min(j,k)); m = (i+j+k)-(l+r); if(l && (l == m || m == r)){ continue; } for(t=(g[r].l_ength()-1); t>=0; --t){ e = g[r][t]; switch(e.x){ case 3: if(!(e.l<=l)){ dp[i][j][k] = 0; } break; case 2: if(!(l<e.l && e.l<=m)){ dp[i][j][k] = 0; } break; case 1: if(!(m<e.l)){ dp[i][j][k] = 0; } break; } } if(r==n){ add_mod(ans,dp[i][j][k]); continue; } add_mod(dp[r+1][j][k],dp[i][j][k]); add_mod(dp[i][r+1][k],dp[i][j][k]); add_mod(dp[i][j][r+1],dp[i][j][k]); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:70:49: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'll' {aka 'long long int'} 70 | add_mod(ans,dp[i][j][k]); | ^~~ a.cc:16:19: note: initializing argument 1 of 'void add_mod(int&, int)' 16 | void add_mod(int& a, int b){ | ~~~~~^
s718382299
p03717
C++
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define INF (1<<30) #define INFLL (1ll<<60) typedef pair<int, int> P; typedef pair<int, P> E; #define MOD (1000000007ll) #define l_ength size void mul_mod(ll& a, ll b){ a *= b; a %= MOD; } void add_mod(ll& a, ll b){ b += MOD; a += b; a %= MOD; } struct edge{ int l, x; }; vector<edge> g[334]; int dp[334][334][334]; int main(void){ int n,m,i,j,k,t,l,r,x; ll ans=0ll; edge e; cin >> n >> m; for(t=0; t<m; ++t){ cin >> l >> r >> x; e.l = l; e.x = x; g[r].push_back(e); } dp[0][0][0] = 1; for(i=0; i<=n; ++i){ for(j=0; j<=n; ++j){ for(k=0; k<=n; ++k){ r = max(i,max(j,k)); l = min(i,min(j,k)); m = (i+j+k)-(l+r); if(l && (l == m || m == r)){ continue; } for(t=(g[r].l_ength()-1); t>=0; --t){ e = g[r][t]; switch(e.x){ case 3: if(!(e.l<=l)){ dp[i][j][k] = 0ll; } break; case 2: if(!(l<e.l && e.l<=m)){ dp[i][j][k] = 0ll; } break; case 1: if(!(m<e.l)){ dp[i][j][k] = 0ll; } break; } } if(r==n){ add_mod(ans,dp[i][j][k]); continue; } add_mod(dp[r+1][j][k],dp[i][j][k]); add_mod(dp[i][r+1][k],dp[i][j][k]); add_mod(dp[i][j][r+1],dp[i][j][k]); } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:73:53: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 73 | add_mod(dp[r+1][j][k],dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:16:18: note: initializing argument 1 of 'void add_mod(ll&, ll)' 16 | void add_mod(ll& a, ll b){ | ~~~~^ a.cc:74:53: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 74 | add_mod(dp[i][r+1][k],dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:16:18: note: initializing argument 1 of 'void add_mod(ll&, ll)' 16 | void add_mod(ll& a, ll b){ | ~~~~^ a.cc:75:53: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 75 | add_mod(dp[i][j][r+1],dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:16:18: note: initializing argument 1 of 'void add_mod(ll&, ll)' 16 | void add_mod(ll& a, ll b){ | ~~~~^
s286647217
p03717
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i) #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;} #define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;} #define ALL(v) v.begin(),v.end() #define Decimal fixed<<setprecision(20) #define INF 1000000000 #define LLINF 1000000000000000000LL #define MOD 1000000007 #define fastcin() cin.tie(0);ios::sync_with_stdio(false) typedef long long ll; typedef pair<int,int> P; int dp[303][303][303]; void modadd(ll &a, ll b){ a += b; a %= MOD; } vector<vector<P>> que(303); int main(){ ll n,m;cin >> n >> m; REP(i,m){ ll a,b,c;cin >> a >> b >> c; que[b].EB(a,c); } dp[0][0][0] = 1; REP(i,n+1){ REP(j,n+1){ REP(k,n+1){ if(dp[i][j][k] == 0)continue; int r = max(i,max(j,k)); REP(ii,que[r].size()){ int cou = 0; if(i >= que[r][ii].FI)cou++; if(j >= que[r][ii].FI)cou++; if(k >= que[r][ii].FI)cou++; if(cou != que[r][ii].SE)dp[i][j][k] = 0; } modadd(dp[r+1][j][k], dp[i][j][k]); modadd(dp[i][r+1][k], dp[i][j][k]); modadd(dp[i][j][r+1], dp[i][j][k]); } } } ll ans = 0; REP(i,n+1){ REP(j,n+1){ REP(k,n+1){ int r = max(i,max(j,k)); if(r == n){ //cout << "seica " << i << " " << j << " " << k << " " << dp[i][j][k] << endl; modadd(ans,dp[i][j][k]); } } } } cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:55:52: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 55 | modadd(dp[r+1][j][k], dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:26:17: note: initializing argument 1 of 'void modadd(ll&, ll)' 26 | void modadd(ll &a, ll b){ | ~~~~^ a.cc:56:52: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 56 | modadd(dp[i][r+1][k], dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:26:17: note: initializing argument 1 of 'void modadd(ll&, ll)' 26 | void modadd(ll &a, ll b){ | ~~~~^ a.cc:57:52: error: cannot bind non-const lvalue reference of type 'll&' {aka 'long long int&'} to a value of type 'int' 57 | modadd(dp[i][j][r+1], dp[i][j][k]); | ~~~~~~~~~~~~^ a.cc:26:17: note: initializing argument 1 of 'void modadd(ll&, ll)' 26 | void modadd(ll &a, ll b){ | ~~~~^
s166617710
p03717
C++
#include<iostream> #include<cstdio> #include<algorithm> using namespace std; #define MAX 330 #define MOD 1000000007 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-')t=true,ch=getchar(); while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar(); return t?-x:x; } void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;} int n,m,f[MAX][MAX][MAX],ans; struct Node{int l,x;}; vector<Node> e[MAX]; bool check(int a,int b,int c) { int r=max(a,max(b,c)); for(int i=0,t=e[r].size();i<t;++i) { int l=e[r][i].l,x=e[r][i].x,s=0; s=(a>=l)+(b>=l)+(c>=l); if(s!=x)return false; } return true; } int main() { n=read();m=read(); for(int i=1;i<=m;++i) { int l=read(),r=read(),x=read(); e[r].push_back((Node){l,x}); } f[0][0][0]=1; for(int i=0;i<=n;++i) for(int j=0;j<=n;++j) for(int k=0;k<=n;++k) { if(!f[i][j][k])continue; if((i&&k&&i==k)||(i&&j&&i==j)||(j&&k&&j==k))continue; if(!check(i,j,k)){f[i][j][k]=0;continue;} int r=max(i,max(j,k)); add(f[r+1][j][k],f[i][j][k]); add(f[i][r+1][k],f[i][j][k]); add(f[i][j][r+1],f[i][j][k]); if(r==n)add(ans,f[i][j][k]); } printf("%d\n",ans); return 0; }
a.cc:18:1: error: 'vector' does not name a type 18 | vector<Node> e[MAX]; | ^~~~~~ a.cc: In function 'bool check(int, int, int)': a.cc:22:23: error: 'e' was not declared in this scope 22 | for(int i=0,t=e[r].size();i<t;++i) | ^ a.cc:25:17: error: 's' was not declared in this scope 25 | s=(a>=l)+(b>=l)+(c>=l); | ^ a.cc:26:23: error: 'x' was not declared in this scope 26 | if(s!=x)return false; | ^ a.cc: In function 'int main()': a.cc:36:17: error: 'e' was not declared in this scope 36 | e[r].push_back((Node){l,x}); | ^
s558535263
p03717
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); int MOD=1e9+7; #define INF 2*1e9 #define N 310000 using namespace std; string alphabet("abcdefghijklmnopqrstuvwxyz"); main(){ int n,m; cin>>n>>m; pair<pii,int> p[400]; rep(i,m){ int l,r,x; cin>>l>>r>>x; p[i]={{r,l},x}; } sort(p,p+m); int dp[400][400][400]={}; dp[0][0][0]=1; rep(i,n){ rep2(j,0,max(i-1,0)){ rep2(k,0,max(0,j-1)){ dp[i+1][i][k]=(dp[i+1][i][k]+dp[i][j][k])%MOD; dp[i+1][j][k]=(dp[i+1][j][k]+dp[i][j][k])%MOD; dp[i+1][i][j]=(dp[i+1][i][j]+dp[i][j][k])%MOD; } } int l=lower_bound(p,p+m,(pair<pii,int>){{i+1,0},0})-p; int r=upper_bound(p,p+m,(pair<pii,int>){{i+1,400},0})-p; rep2(j,0,i){ rep2(k,0,max(0,j-1)){ for(int ii=l;ii<r;ii++) int count=1,s=p[ii].first.second; if(s<=k){ count++; } if(s<=j){ count++; } if(count!=p[ii].second){ dp[i+1][j][k]=0; } } } } } int ans=0; rep2(j,0,n-1){ rep2(k,0,j-1){ ans=(ans+dp[n][j][k])%MOD; } } cout<<ans; return 0; }
a.cc:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 17 | main(){ | ^~~~ a.cc: In function 'int main()': a.cc:43:24: error: 's' was not declared in this scope 43 | if(s<=k){ | ^ a.cc:44:30: error: no post-increment operator for type 44 | count++; | ^~ a.cc:46:24: error: 's' was not declared in this scope 46 | if(s<=j){ | ^ a.cc:47:30: error: no post-increment operator for type 47 | count++; | ^~ a.cc:49:33: error: 'ii' was not declared in this scope; did you mean 'i'? 49 | if(count!=p[ii].second){ | ^~ | i a.cc: At global scope: a.cc:3:21: error: expected unqualified-id before 'for' 3 | #define rep2(i,a,b) for(int i=a;i<=b;++i) | ^~~ a.cc:57:5: note: in expansion of macro 'rep2' 57 | rep2(j,0,n-1){ | ^~~~ a.cc:57:10: error: 'j' does not name a type 57 | rep2(j,0,n-1){ | ^ a.cc:3:33: note: in definition of macro 'rep2' 3 | #define rep2(i,a,b) for(int i=a;i<=b;++i) | ^ a.cc:3:38: error: expected unqualified-id before '++' token 3 | #define rep2(i,a,b) for(int i=a;i<=b;++i) | ^~ a.cc:57:5: note: in expansion of macro 'rep2' 57 | rep2(j,0,n-1){ | ^~~~ a.cc:62:5: error: 'cout' does not name a type 62 | cout<<ans; | ^~~~ a.cc:63:5: error: expected unqualified-id before 'return' 63 | return 0; | ^~~~~~ a.cc:64:1: error: expected declaration before '}' token 64 | } | ^
s882752607
p03717
C++
#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include "bits/stdc++.h" // define macro "/D__MAI" using namespace std; typedef long long int ll; #define xprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__) #define debugv(v) {printf("L%d %s > ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;} #define debuga(m,w) {printf("L%d %s > ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;} #define debugaa(m,h,w) {printf("L%d %s >\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}} #define ALL(v) (v).begin(),(v).end() #define repeat(cnt,l) for(auto cnt=0ll;cnt<(l);++cnt) #define iterate(cnt,b,e) for(auto cnt=(b);cnt!=(e);++cnt) #define MD 1000000007ll #define PI 3.1415926535897932384626433832795 template<typename T1, typename T2> ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; } template<typename iterator> inline size_t argmin(iterator begin, iterator end) { return distance(begin, min_element(begin, end)); } template<typename iterator> inline size_t argmax(iterator begin, iterator end) { return distance(begin, max_element(begin, end)); } template<typename T> T& maxset(T& to, const T& val) { return to = max(to, val); } template<typename T> T& minset(T& to, const T& val) { return to = min(to, val); } mt19937_64 randdev(8901016); inline ll rand_range(ll l, ll h) { return uniform_int_distribution<ll>(l, h)(randdev); } #ifdef __MAI #define getchar_unlocked getchar #define putchar_unlocked putchar #endif #ifdef __VSCC #define getchar_unlocked _getchar_nolock #define putchar_unlocked _putchar_nolock #endif namespace { #define isvisiblechar(c) (0x21<=(c)&&(c)<=0x7E) class MaiScanner { public: template<typename T> void input_integer(T& var) { var = 0; T sign = 1; int cc = getchar_unlocked(); for (; cc<'0' || '9'<cc; cc = getchar_unlocked()) if (cc == '-') sign = -1; for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked()) var = (var << 3) + (var << 1) + cc - '0'; var = var*sign; } inline int c() { return getchar_unlocked(); } inline MaiScanner& operator>>(int& var) { input_integer<int>(var); return *this; } inline MaiScanner& operator>>(long long& var) { input_integer<long long>(var); return *this; } inline MaiScanner& operator>>(string& var) { int cc = getchar_unlocked(); for (; !isvisiblechar(cc); cc = getchar_unlocked()); for (; isvisiblechar(cc); cc = getchar_unlocked()) var.push_back(cc); } template<typename IT> void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; } MaiScanner scanner; class llmod { public: const ll MOD = MD; private: ll val; inline ll cut(ll v) const { return ((v%MOD) + MOD) % MOD; } public: llmod() : MOD(MD), val(0) {} llmod(ll num, ll m = MD) : MOD(m), val(cut(num)) {} llmod(const llmod& lm, ll m) : MOD(m), val(lm.val) {} inline ll operator*() const { return val; } inline llmod& operator=(const llmod& lm) { val = lm.val; return *this; } inline llmod& operator=(ll v) { val = cut(v); return *this; } inline llmod& operator+=(ll v) { val = cut(val + v); return *this; } inline llmod& operator+=(const llmod& l) { val = cut(val + l.val); return *this; } inline llmod& operator-=(ll v) { val = cut(val - v); return *this; } inline llmod& operator-=(const llmod& l) { val = cut(val - l.val); return *this; } inline llmod& operator*=(ll v) { val = cut(val * v); return *this; } inline llmod& operator*=(const llmod& l) { val = cut(val * l.val); return *this; } inline llmod& operator++() { val = (val + 1) % MOD; return *this; } inline llmod operator++(int) { llmod t = *this; val = (val + 1) % MOD; return t; } }; ostream& operator<<(ostream& os, const llmod& l) { os << *l; return os; } inline llmod operator+(llmod t, const llmod& r) { return t += r; } inline llmod operator-(llmod t, const llmod& r) { return t -= r; } inline llmod operator*(llmod t, const llmod& r) { return t *= r; } // MEMO : 逆元...powm(n,MD-2) llmod pow(llmod x, ll p) { llmod y = 1; while (0 < p) { if (p % 2) y *= x; x *= x; p /= 2; } return y; } inline llmod& operator/=(llmod& l, const llmod& r) { return l *= pow(r, r.MOD - 2); } /* 2色に無い色を加えて,3色にする => 組み合わせ数は 2色のパターンと一致 */ int n, m; vector<vector<pair<int, int>>> limit; llmod dp[302][302][302]; int main() { scanner >> n >> m; limit.resize(n+1); repeat(i, m) { int l, r, x; scanner >> l >> r >> x; //--l; --r; limit[r].emplace_back(l, x); } llmod ans = 0; // どの色も存在しない dp[0][0][0] = 1; repeat(r, n+1) { repeat(g, n+1) { repeat(b, n+1) { if (dp[r][g][b] == 0) continue; int right = max(max(r, g), b); array<int, 3> p = { r,g,b }; sort(ALL(p)); for (auto lx : limit[right]) { int l = lx.first; int c = 1 + (l <= p[1]) + (l <= p[0]); if (lx.second != c) { dp[r][g][b] = 0; goto l_nxt; } } dp[right + 1][g][b] += dp[r][g][b]; dp[r][right + 1][b] += dp[r][g][b]; dp[r][g][right + 1] += dp[r][g][b]; if (right == n) ans += dp[r][g][b]; l_nxt:; } } } cout << *ans << endl; return 0; }
a.cc: In member function '{anonymous}::MaiScanner& {anonymous}::MaiScanner::operator>>(std::string&)': a.cc:68:9: warning: no return statement in function returning non-void [-Wreturn-type] 68 | } | ^ a.cc: In function 'int main()': a.cc:158:33: error: no match for 'operator==' (operand types are 'llmod' and 'int') 158 | if (dp[r][g][b] == 0) continue; | ~~~~~~~~~~~ ^~ ~ | | | | | int | llmod In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181, from a.cc:3: /usr/include/c++/14/bits/regex.h:1103:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const sub_match<_BiIter>&)' 1103 | operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1103:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1199:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)' 1199 | operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1199:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1274:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator==(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)' 1274 | operator==(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1274:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1366:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)' 1366 | operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1366:5: note: template argument deduction/substitution failed: a.cc:158:36: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1441:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)' 1441 | operator==(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1441:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1534:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)' 1534 | operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1534:5: note: template argument deduction/substitution failed: a.cc:158:36: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'int' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:1613:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator==(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)' 1613 | operator==(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1613:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::__cxx11::sub_match<_BiIter>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/regex.h:2186:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator==(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)' 2186 | operator==(const match_results<_Bi_iter, _Alloc>& __m1, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:2186:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::__cxx11::match_results<_BiIter, _Alloc>' 158 | if (dp[r][g][b] == 0) continue; | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/bits/stl_pair.h:1033:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator==(const pair<_T1, _T2>&, const pair<_T1, _T2>&)' 1033 | operator==(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1033:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::pair<_T1, _T2>' 158 | if (dp[r][g][b] == 0) continue; | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/stl_iterator.h:441:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)' 441 | operator==(const reverse_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:441:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::reverse_iterator<_Iterator>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/stl_iterator.h:486:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)' 486 | operator==(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:486:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::reverse_iterator<_Iterator>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/stl_iterator.h:1667:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)' 1667 | operator==(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1667:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::move_iterator<_IteratorL>' 158 | if (dp[r][g][b] == 0) continue; | ^ /usr/include/c++/14/bits/stl_iterator.h:1737:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator==(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)' 1737 | operator==(const move_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1737:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::move_iterator<_IteratorL>' 158 | if (dp[r][g][b] == 0) continue; | ^ In file included from /usr/include/c++/14/bits/char_traits.h:42, from /usr/include/c++/14/string:42, 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/postypes.h:192:5: note: candidate: 'template<class _StateT> bool std::operator==(const fpos<_StateT>&, const fpos<_StateT>&)' 192 | operator==(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/postypes.h:192:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::fpos<_StateT>' 158 | if (dp[r][g][b] == 0) continue; | ^ In file included from /usr/include/c++/14/string:43: /usr/include/c++/14/bits/allocator.h:235:5: note: candidate: 'template<class _T1, class _T2> bool std::operator==(const allocator<_CharT>&, const allocator<_T2>&)' 235 | operator==(const allocator<_T1>&, const allocator<_T2>&) | ^~~~~~~~ /usr/include/c++/14/bits/allocator.h:235:5: note: template argument deduction/substitution failed: a.cc:158:36: note: 'llmod' is not derived from 'const std::allocator<_CharT>' 158 | if (dp[r][g][b] == 0) continue; | ^ In file included from /usr/include/c++/14/bits/basic_string.h:47, from /usr/include/c++/14/string:54: /usr/include/c++/14/string_view:629:5: note: candidate: 'template<class _CharT, class _Traits> constexpr bool std::operator==(basic_string_view<_Ch
s165304989
p03717
C++
#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<queue> #include<map> #include<cstring> #include<string> #include <math.h> #include<algorithm> // #include <boost/multiprecision/cpp_int.hpp> #include<functional> // #define int long long #define inf 1000000007 #define pa pair<int,int> #define ll long long #define pal pair<double,pa> #define ppa pair<int,int> #define ppap pair<int,pa> #define ssa pair<string,int> #define mp make_pair #define pb push_back #define EPS (1e-10) #define equals(a,b) (fabs((a)-(b))<EPS) using namespace std; class Point{ public: double x,y; Point(double x=0,double y=0):x(x),y(y) {} Point operator + (Point p) {return Point(x+p.x,y+p.y);} Point operator - (Point p) {return Point(x-p.x,y-p.y);} Point operator * (double a) {return Point(x*a,y*a);} Point operator / (double a) {return Point(x/a,y/a);} double absv() {return sqrt(norm());} double norm() {return x*x+y*y;} bool operator < (const Point &p) const{ return x != p.x ? x<p.x: y<p.y; } bool operator == (const Point &p) const{ return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS; } }; typedef Point Vector; struct Segment{ Point p1,p2; }; double dot(Vector a,Vector b){ return a.x*b.x+a.y*b.y; } double cross(Vector a,Vector b){ return a.x*b.y-a.y*b.x; } bool parareru(Point a,Point b,Point c,Point d){ // if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl; return abs(cross(a-b,d-c))<EPS; } double distance_ls_p(Point a, Point b, Point c) { if ( dot(b-a, c-a) < EPS ) return (c-a).absv(); if ( dot(a-b, c-b) < EPS ) return (c-b).absv(); return abs(cross(b-a, c-a)) / (b-a).absv(); } bool is_intersected_ls(Segment a,Segment b) { if(a.p1==b.p1||a.p2==b.p1||a.p1==b.p2||a.p2==b.p2) return false; if(parareru((a.p2),(a.p1),(a.p1),(b.p2))&&parareru((a.p2),(a.p1),(a.p1),(b.p1))){ // cout<<"sss"<<endl; if(dot(a.p1-b.p1,a.p1-b.p2)<EPS) return true; if(dot(a.p2-b.p1,a.p2-b.p2)<EPS) return true; if(dot(a.p1-b.p1,a.p2-b.p1)<EPS) return true; if(dot(a.p1-b.p2,a.p2-b.p2)<EPS) return true; return false; } else return ( cross(a.p2-a.p1, b.p1-a.p1) * cross(a.p2-a.p1, b.p2-a.p1) < EPS ) && ( cross(b.p2-b.p1, a.p1-b.p1) * cross(b.p2-b.p1, a.p2-b.p1) < EPS ); } double segment_dis(Segment a,Segment b){ if(is_intersected_ls(a,b))return 0; double r=distance_ls_p(a.p1, a.p2, b.p1); r=min(r,distance_ls_p(a.p1, a.p2, b.p2)); r=min(r,distance_ls_p(b.p1, b.p2, a.p2)); r=min(r,distance_ls_p(b.p1, b.p2, a.p1)); return r; } Point intersection_ls(Segment a, Segment b) { Point ba = b.p2-b.p1; double d1 = abs(cross(ba, a.p1-b.p1)); double d2 = abs(cross(ba, a.p2-b.p1)); double t = d1 / (d1 + d2); return a.p1 + (a.p2-a.p1) * t; } string itos( int i ) { ostringstream s ; s << i ; return s.str() ; } int gcd(int v,int b){ if(v>b) return gcd(b,v); if(v==b) return b; if(b%v==0) return v; return gcd(v,b%v); } double distans(double x1,double y1,double x2,double y2){ double rr=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2); return sqrt(rr); } /* int pr[100010]; //int inv[100010]; */ int beki(int wa,int rr,int warukazu){ if(rr==0) return 1ll; if(rr==1) return wa%warukazu; if(rr%2==1) return (beki(wa,rr-1,warukazu)*wa)%warukazu; int zx=beki(wa,rr/2,warukazu); return (zx*zx)%warukazu; } /* void gya(){ pr[0]=1; for(int i=1;i<100010;i++){ pr[i]=(pr[i-1]*i)%inf; } for(int i=0;i<100010;i++) inv[i]=beki(pr[i],inf-2); } */ //sort(ve.begin(),ve.end(),greater<int>()); //----------------kokomade tenpure------------ //vector<double> ans(100000000),ans2(100000000); int dp[400][400][400]={0}; int l[400],r[400],x[400]; vector<pa> ve[400]; signed main(){ int n,m; cin>>n>>m; for(int i=1;i<=m;i++){ cin>>l[i]>>r[i]>>x[i]; ve[r[i]].pb(mp(l[i],x[i])); } dp[0][0][0]=1; int mod=inf; for(int a=0;a<=n;a++)for(int b=0;b<=n;b++)for(int c=0;c<=n;c++){ int m=max({a,b,c}); /* if(m==0){ dp[m+1][b][c]=dp[a][b][c]%mod; dp[a][m+1][c]=dp[a][b][c]%mod; dp[a][b][m+1]=dp[a][b][c]%mod; continue; } */ if(m==n) continue; dp[m+1][b][c]+=dp[a][b][c]%mod; dp[m+1][b][c]%=mod dp[a][m+1][c]+=dp[a][b][c]%mod; dp[a][m+1][c]%=mod dp[a][b][m+1]+=dp[a][b][c]%mod; dp[a][b][m+1]%=mod for(int i=0;i<ve[m+1].size();i++){ pa z=ve[m+1][i]; if(z.second==1)if(max(b,c)>=z.first) dp[m+1][b][c]=0; if(z.second==2) if(!(max(b,c)>=z.first && min(b,c)<z.first))dp[m+1][b][c]=0; if(z.second==3) if(min(b,c)<z.first)dp[m+1][b][c]=0; if(z.second==1)if(max(a,c)>=z.first) dp[a][m+1][c]=0; if(z.second==2) if(!(max(a,c)>=z.first && min(a,c)<z.first))dp[a][m+1][c]=0; if(z.second==3) if(min(a,c)<z.first)dp[a][m+1][c]=0; if(z.second==1)if(max(b,a)>=z.first) dp[a][b][m+1]=0; if(z.second==2) if(!(max(b,a)>=z.first && min(b,a)<z.first))dp[a][b][m+1]=0; if(z.second==3) if(min(b,a)<z.first)dp[a][b][m+1]=0; } // cout<<m+1<<" "<<b<<" "<<c<<" "<<dp[m+1][b][c]<<endl; // cout<<a<<" "<<m+1<<" "<<c<<" "<<dp[a][m+1][c]<<endl; // cout<<a<<" "<<b<<" "<<m+1<<" "<<dp[a][b][m+1]<<endl; } int ans=0; for(int i=0;i<=n;i++)for(int j=0;j<=n;j++){ ans += dp[n][i][j]; ans %=mod; ans += dp[i][n][j]; ans %=mod; ans += dp[j][i][n]; ans %=mod; } cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:165:35: error: expected ';' before 'dp' 165 | dp[m+1][b][c]%=mod | ^ | ; 166 | dp[a][m+1][c]+=dp[a][b][c]%mod; | ~~ a.cc:167:35: error: expected ';' before 'dp' 167 | dp[a][m+1][c]%=mod | ^ | ; 168 | dp[a][b][m+1]+=dp[a][b][c]%mod; | ~~ a.cc:169:35: error: expected ';' before 'for' 169 | dp[a][b][m+1]%=mod | ^ | ; 170 | for(int i=0;i<ve[m+1].size();i++){ | ~~~ a.cc:170:29: error: 'i' was not declared in this scope 170 | for(int i=0;i<ve[m+1].size();i++){ | ^
s457830813
p03717
C++
#include <stdio.h> #include <algorithm> #include <vector> const int P = 1000000007; using namespace std; struct otrezok { int l, r, c; }; otrezok o[512]; vector<otrezok> p[512]; bool operator < (otrezok a, otrezok b) { if (a.r == b.r) return a.l < b.l; return a.r < b.r; } int n, m; int d[2][4][301][301]; int howMany(int l, int R, int G, int B) { return (l <= R) + (l <= G) + (l <= B); } int F(int lastVal, int curVal, int R, int G, int B, int pos) { pos++; for (int i = 0; i < p[pos].size(); i++) { int h = howMany(p[pos][i].l, R, G, B); if (h != p[pos][i].c) return 0; } return (curVal + lastVal) % P; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d%d%d", &o[i].l, &o[i].r, &o[i].c); } sort(o, o + m); for (int i = 0; i < m; i++) { p[o[i].r].push_back(o[i]); } d[0][1][0][0] = 1; d[0][2][0][0] = 1; d[0][3][0][0] = 1; int cur = 0; for (int i = 1; i < n; i++) { cur = 1 - cur; memset(d[cur], 0, sizeof(d[cur])); for (int j = 1; j <= 3; j++) { for (int c1 = 0; c1 <= n; c1++) { for (int c2 = 0; c2 <= n; c2++) { for (int h = 1; h <= 3; h++) { if (h == j) { if (h == 1) { //RGB d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], i, c1, c2, i); } else if (h == 2) { //GRB d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], c1, i, c2, i); } else if (h == 3) { //BRG d[cur][j][c1][c2] = F(d[1 - cur][j][c1][c2], d[1 - cur][j][c1][c2], c1, c2, i, i); } } else { //RGB //GRB //BRG if (h == 1) { //RED if (j == 2) { //WAS GREEN // R G B G R B d[cur][h][i - 1][c2] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c2], i, i - 1, c2, i); } else { //WAS BLUE // R G B B R G d[cur][h][c2][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c2][i - 1], i, c2, i - 1, i); } } if (h == 2) { //GREEN if (j == 1) { //WAS RED // G R B R G B d[cur][h][i - 1][c2] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c2], i - 1, i, c2, i); } else { //WAS BLUE // G R B B R G d[cur][h][c1][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c1][i - 1], c1, i, i - 1, i); } } if (h == 3) { //BLUE if (j == 1) { //RED // B R G R G B d[cur][h][i - 1][c1] = F(d[1 - cur][j][c1][c2], d[cur][h][i - 1][c1], i - 1, c1, i, i); } else { //GREEN // B R G G R B d[cur][h][c1][i - 1] = F(d[1 - cur][j][c1][c2], d[cur][h][c1][i - 1], c1, i - 1, i, i); } } } } } } } } int total = 0; for (int i = 1; i <= 3; i++) { for (int j = 0; j <= n; j++) { for (int k = 0; k <= n; k++) { total = (total + d[cur][i][j][k]) % P; } } } printf("%d\n", total); return 0; }
a.cc: In function 'int main()': a.cc:56:17: error: 'memset' was not declared in this scope 56 | memset(d[cur], 0, sizeof(d[cur])); | ^~~~~~ a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 3 | #include <vector> +++ |+#include <cstring> 4 |
s417139491
p03717
C++
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <iomanip> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; int n; struct CHECK { int l; int r; int x; }; CHECK check_roules[301][300]; int m[301] = {0}; int c[301][301][301]; int new_chk(int i, int r, int g, int b) { vector<int> v; v.push_back(r); v.push_back(g); v.push_back(b); sort(v.begin(), v.end()); int* ret = &c[i][v[0]][v[1]]; if (*ret != -1) { return *ret; } for (int j = 0 ; j < m[i] ; j++) { if (check_roules[i][j].l <= v[0]) { if (check_roules[i][j].x != 3) { return *ret = 0; } } else if (check_roules[i][j].l <= v[1]) { if (check_roules[i][j].x != 2) { return *ret = 0; } } else { if (check_roules[i][j].x != 1) { return *ret = 0; } } } if (i == n) { return *ret = 1; } return *ret = ((new_chk(i + 1, i + 1, g, b) + new_chk(i + 1, r, i + 1, b) + new_chk(i + 1, r, g, i + 1)) % 1000000007); } int main() { cin >> n; int M; cin >> M; for (int i = 0 ; i < M ; i++) { CHECK check_roule; cin >> check_roule.l; cin >> check_roule.r; cin >> check_roule.x; check_roules[check_roule.r][m[check_roule.r]] = check_roule; (m[check_roule.r])++; } memset(c, -1, sizeof(c)); cout << new_chk(0, 0, 0, 0) << endl; return 0; }
a.cc: In function 'int main()': a.cc:72:9: error: 'memset' was not declared in this scope 72 | memset(c, -1, sizeof(c)); | ^~~~~~ a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 10 | #include <algorithm> +++ |+#include <cstring> 11 | using namespace std;
s359928763
p03717
C++
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <iomanip> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; int n; struct CHECK { int l; int r; int x; }; CHECK check_roules[301][300]; int m[301] = {0}; int c[301][301][301]; int new_chk(int i, int r, int g, int b) { vector<int> v; v.push_back(r); v.push_back(g); v.push_back(b); sort(v.begin(), v.end()); int& ret = c[i][v[0]][v[1]]; if (ret != -1) { return ret; } for (int j = 0 ; j < m[i] ; j++) { if (check_roules[i][j].l <= v[0]) { if (check_roules[i][j].x != 3) { return ret = 0; } } else if (check_roules[i][j].l <= v[1]) { if (check_roules[i][j].x != 2) { return ret = 0; } } else { if (check_roules[i][j].x != 1) { return ret = 0; } } } if (i == n) { return ret = 1; } return ret = ((new_chk(i + 1, i + 1, g, b) + new_chk(i + 1, r, i + 1, b) + new_chk(i + 1, r, g, i + 1)) % 1000000007); } int main() { cin >> n; int M; cin >> M; for (int i = 0 ; i < M ; i++) { CHECK check_roule; cin >> check_roule.l; cin >> check_roule.r; cin >> check_roule.x; check_roules[check_roule.r][m[check_roule.r]] = check_roule; (m[check_roule.r])++; } memset(c, -1, sizeof(c)); cout << new_chk(0, 0, 0, 0) << endl; return 0; }
a.cc: In function 'int main()': a.cc:72:9: error: 'memset' was not declared in this scope 72 | memset(c, -1, sizeof(c)); | ^~~~~~ a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 10 | #include <algorithm> +++ |+#include <cstring> 11 | using namespace std;
s620444982
p03717
C++
#include <stdio.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <iomanip> #include <string> #include <map> #include <vector> #include <algorithm> using namespace std; int n; struct CHECK { int l; int r; int x; }; CHECK check_roules[301][300]; int m[301] = {0}; int c[301][301][301]; int new_chk(int i, int r, int g, int b) { vector<int> v; v.push_back(r); v.push_back(g); v.push_back(b); sort(v.begin(), v.end()); int& ret = c[i][v[0]][v[1]]; if (ret != -1) { return ret; } for (int j = 0 ; j < m[i] ; j++) { if (check_roules[i][j].l <= v[0]) { if (check_roules[i][j].x != 3) { return ret = 0; } } if (check_roules[i][j].l <= v[0]) { if (check_roules[i][j].x != 2) { return ret = 0; } } if (check_roules[i][j].l <= v[0]) { if (check_roules[i][j].x != 1) { return ret = 0; } } } if (i == n) { return ret = 1; } return ret = ((new_chk(i + 1, i + 1, g, b) + new_chk(i + 1, r, i + 1, b) + new_chk(i + 1, r, g, i + 1)) % 1000000007); } int main() { cin >> n; int M; cin >> M; for (int i = 0 ; i < M ; i++) { CHECK check_roule; cin >> check_roule.l; cin >> check_roule.r; cin >> check_roule.x; check_roules[check_roule.r][m[check_roule.r]] = check_roule; (m[check_roule.r])++; } memset(c, -1, sizeof(c)); cout << new_chk(0, 0, 0, 0) << endl; return 0; }
a.cc: In function 'int main()': a.cc:74:9: error: 'memset' was not declared in this scope 74 | memset(c, -1, sizeof(c)); | ^~~~~~ a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 10 | #include <algorithm> +++ |+#include <cstring> 11 | using namespace std;
s864294953
p03717
C++
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <set> #include <cstdlib> #include <vector> using namespace std; const int maxn = 310; const int mod = 1000000007; vector<int> end[maxn]; int f[maxn][maxn][maxn]; set<int> s; int l[maxn], r[maxn], x[maxn]; bool check(int r,int g, int b) { if ((r==g && r!=0) || (g==b&&g!=0) || (r==b&&r!=0)) return false; int k = max(r,max(g,b)); s.clear(); s.insert(r); s.insert(g); s.insert(b); s.erase(k); int t1 = *s.begin(); s.erase(t1); int t2 = *s.begin(); for (int i=0;i<(int)end[k].size();i++) { if (l[end[k][i]]<=k && l[end[k][i]] >= max(t1,t2)+1) { if (x[end[k][i]] != 1) return false; } if (l[end[k][i]] <= max(t1,t2) && l[end[k][i]] > min(t1,t2)) { if (x[end[k][i]] != 2) return false; } if (l[end[k][i]] <= min(t1,t2)) { if (x[end[k][i]] != 3) return false; } } return true; } int main() { //freopen("E.in","r",stdin); int n,m; scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { scanf("%d%d%d",&l[i], &r[i], &x[i]); end[r[i]].push_back(i); } f[0][0][0] = 1; for (int r=0;r<=n;r++) { for (int g=0;g<=n;g++) { for (int b=0;b<=n;b++) { if (!check(r,g,b)) { f[r][g][b] = 0; continue; } //cout<<r<<" "<<g<<" "<<b<<" "<<f[r][g][b]<<endl; int k = max(r,max(g,b)); // R f[k+1][g][b] = (f[k+1][g][b] + f[r][g][b]) % mod; // G f[r][k+1][b] = (f[r][k+1][b] + f[r][g][b]) % mod; // B f[r][g][k+1] = (f[r][g][k+1] + f[r][g][b]) % mod; } } } int sum = 0; for (int r=0;r<=n;r++) { for (int g=0;g<=n;g++) { for (int b=0;b<=n;b++) if (max(r,max(g,b)) == n) sum = (sum + f[r][g][b]) % mod; } } printf("%d\n",sum); return 0; }
a.cc: In function 'bool check(int, int, int)': a.cc:27:29: error: reference to 'end' is ambiguous 27 | for (int i=0;i<(int)end[k].size();i++) | ^~~ 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:1: /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ In file included from /usr/include/c++/14/bits/range_access.h:36: /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:13:13: note: 'std::vector<int> end [310]' 13 | vector<int> end[maxn]; | ^~~ a.cc:29:23: error: reference to 'end' is ambiguous 29 | if (l[end[k][i]]<=k && l[end[k][i]] >= max(t1,t2)+1) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:13:13: note: 'std::vector<int> end [310]' 13 | vector<int> end[maxn]; | ^~~ a.cc:29:42: error: reference to 'end' is ambiguous 29 | if (l[end[k][i]]<=k && l[end[k][i]] >= max(t1,t2)+1) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:13:13: note: 'std::vector<int> end [310]' 13 | vector<int> end[maxn]; | ^~~ a.cc:31:31: error: reference to 'end' is ambiguous 31 | if (x[end[k][i]] != 1) return false; | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:13:13: note: 'std::vector<int> end [310]' 13 | vector<int> end[maxn]; | ^~~ a.cc:33:23: error: reference to 'end' is ambiguous 33 | if (l[end[k][i]] <= max(t1,t2) && l[end[k][i]] > min(t1,t2)) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:13:13: note: 'std::vector<int> end [310]' 13 | vector<int> end[maxn]; | ^~~ a.cc:33:53: error: reference to 'end' is ambiguous 33 | if (l[end[k][i]] <= max(t1,t2) && l[end[k][i]] > min(t1,t2)) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c+
s405767859
p03717
C++
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<string> #include<stack> #include<queue> #include<vector> #include<map> #include<set> #include<algorithm> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<=n;i++) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define pb(x) push_back(x) #define eb(x,y) emplace_back(x,y) #define MOD 1000000007 #define MAX 1000000001 #define INF 1410065408 #define EPS 1e-9 using namespace std; typedef long long ll; typedef pair<ll, ll> P; struct edge{int from, to; ll cost;}; signed main(){ int N, M; cin >> N >> M; vector< pair<int, int> > conds[N+1]; rep(M){ int l, r, x; cin >> l >> r >> x; conds[r].emplace_back(l, x); } vector< vector< vector<int> > > dp(N+1, vector< vector<int> >(N+1, vector<int>(N+1, 0))); dp[0][0][0] = 1; rep(N){ repp(j, N){ repp(k, N){ int r = max(i, max(j, k)); dp[r+1][j][k] += dp[i][j][k]; dp[i][r+1][k] += dp[i][j][k]; dp[i][j][r+1] += dp[i][j][k]; for(auto p : conds[r+1]){ int l = p.first, x = p.second; vector<int> comp(3,0); if(l <= i) comp[0] = 1; if(l <= j) comp[1] = 1; if(l <= k) comp[2] = 1; if(comp[1] + comp[2] + 1 != x) dp[r+1][j][k] = 0; if(comp[0] + comp[2] + 1 != x) dp[i][r+1][k] = 0; if(comp[0] + comp[1] + 1 != x) dp[i][j][r+1] = 0; } } } } ll ans = 0; repp(i, N){ ll tmp = 0; reppp(j, N){ tmp += dp[i][j][N] % MOD; tmp += dp[j][i][N] % MOD; tmp += dp[i][N][j] % MOD; tmp += dp[j][N][i] % MOD; tmp += dp[N][i][j] % MOD; tmp += dp[N][j][i] % MOD; } ans += tmp % MOD; } cout << ans % MOD << endl; return 0; }
a.cc:68:27: error: macro "reppp" requires 3 arguments, but only 2 given 68 | reppp(j, N){ | ^ a.cc:15:9: note: macro "reppp" defined here 15 | #define reppp(i, m, n) for(int i=m;i<=n;i++) | ^~~~~ a.cc: In function 'int main()': a.cc:68:17: error: 'reppp' was not declared in this scope 68 | reppp(j, N){ | ^~~~~
s703950753
p03717
C++
#include <iostream> #include <vector> using namespace std; const int MAXN = 305; const int MOD = 1000000007; vector < pair<int,int> > A[MAXN]; int dp[MAXN][MAXN][MAXN]; void mod_add(int &x, int y) { x = (x + y)%MOD; } int main() { int n,m; scanf("%d %d", &n, &m); for (int i = 0; i < m; ++i) { int ty, l, r; scanf("%d %d %d", &l, &r, &ty); A[r].push_back(make_pair(l,ty)); } dp[0][0][0] = 1; int ans = 0; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { for (int k = 0; k <= n; ++k) { int pos[] = {i,j,k}; sort(pos, pos+3); for (int ii = 0; ii < A[pos[2]].size(); ++ii) { int l = A[pos[2]][ii].first; int num = A[pos[2]][ii].second; if(num == 1 && pos[1] >= l) dp[i][j][k] = 0; if(num == 2 && (pos[0] >= l || pos[1] < l)) dp[i][j][k] = 0; if(num == 3 && pos[0] < l) dp[i][j][k] = 0; } mod_add(dp[pos[2] + 1][j][k], dp[i][j][k]); mod_add(dp[i][pos[2] + 1][k], dp[i][j][k]); mod_add(dp[i][j][pos[2] + 1], dp[i][j][k]); if(pos[2] == n) mod_add(ans, dp[i][j][k]); } } } printf("%d\n", ans); return 0; }
a.cc: In function 'int main()': a.cc:31:33: error: 'sort' was not declared in this scope; did you mean 'short'? 31 | sort(pos, pos+3); | ^~~~ | short
s384240742
p03717
C++
♨♨♨♨♨♨♨♨♨♨ #include "bits/stdc++.h" #define int ll using namespace std; typedef long long ll; typedef pair<int,int> pii; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define all(a) (a).begin(),(a).end() #define pb emplace_back #define INF (1LL<<59) const ll MOD = 1e9+7; //0-index 半開区間セグツリー(値の更新or加算 , 最小値or最大値or和) verified AOJ DSL_2,DSL_3 template<class T> class segtree{ private: vector<T> dat; int _size; //the number of leaves T _init; public: segtree(int __size=0 , T init=numeric_limits<T>::max() ):_size(__size) , _init(init){ if(__size==0)return ; int x=1; while(x<_size)x*=2; _size = x; dat.resize(_size*2); } void init(vector<T> v){ for(int i=_size;i<_size+v.size();i++) dat[i] = v[i-_size]; for(int i=_size-1;i>=1;i--)dat[i] = min(dat[i*2],dat[i*2+1]); //minimum } void update(int m,T x){ int i = m+_size; dat[i] = x; //initialize for(; i!=1; i/=2){ dat[i/2] = min(dat[i],dat[i^1]); //minimum } } // call find(s,t) T find(int s,int t,int num=1,int l=0,int r=-1){ if(r==-1)r=_size; //I couldn't "int b=_size". if(r<=s||t<=l)return _init; if(s<=l&&r<=t)return dat[num]; return min( find(s,t,num*2,l,(l+r)/2) , find(s,t,num*2+1,(l+r)/2,r) ); //minimum } int size(){return _size;} }; int bitcount[]={0,1,1,2,1,2,2,3}; int dp[301][301][10]; int dfs(int l, int r, int bit, segtree<int> &seg){ // cout<<l<<" "<<r<<" "<<bitset<3>(bit)<<endl; if(seg.find(l,r)<bitcount[bit])return 0; if(r-l==1 && bitcount[bit]==1)return 1; if(dp[l][r][bit]!=-1)return dp[l][r][bit]; dp[l][r][bit] = 0; for(int i=l+1;i<r;i++){ rep(j,8){ rep(k,8){ if( (j|k)!=bit )continue; (dp[l][r][bit]+=(dfs(l,i,j,seg)*dfs(i,r,k,seg))%MOD)%=MOD; } } } // cout<<l<<" "<<r<<" "<<bitset<3>(bit)<<" = "<<dp[l][r][bit]<<endl; return dp[l][r][bit]; } signed main(){ rep(i,301)rep(j,301)rep(k,8)dp[i][j][k] = -1; int n,m; cin>>n>>m; vector<int> L(m),R(m),X(m); rep(i,m){ cin>>L[i]>>R[i]>>X[i]; L[i]--; } vector<int> v(n,INF); rep(i,m){ for(int j=L[i];j<R[i];j++){ v[j] = min(v[j],X[i]); } } segtree<int> seg(n); rep(i,v.size()){ seg.update(i,v[i]); } int ans = 0; rep(i,8){ int res = dfs(0,n,i,seg); ans+=res; cout<<res<<endl; } cout<<ans<<endl; }
a.cc:1:1: error: extended character ♨ is not valid in an identifier 1 | ♨♨♨♨♨♨♨♨♨♨ | ^ a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: extended character ♨ is not valid in an identifier a.cc:1:1: error: '\U00002668\U00002668\U00002668\U00002668\U00002668\U00002668\U00002668\U00002668\U00002668\U00002668' does not name a type 1 | ♨♨♨♨♨♨♨♨♨♨ | ^~~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:62, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:3: /usr/include/c++/14/ext/type_traits.h:164:35: error: 'constexpr const bool __gnu_cxx::__is_null_pointer' redeclared as different kind of entity 164 | __is_null_pointer(std::nullptr_t) | ^ /usr/include/c++/14/ext/type_traits.h:159:5: note: previous declaration 'template<class _Type> constexpr bool __gnu_cxx::__is_null_pointer(_Type)' 159 | __is_null_pointer(_Type) | ^~~~~~~~~~~~~~~~~ /usr/include/c++/14/ext/type_traits.h:164:26: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'? 164 | __is_null_pointer(std::nullptr_t) | ^~~~~~~~~ In file included from /usr/include/c++/14/cstddef:50, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:41: /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_pair.h:60, from /usr/include/c++/14/bits/stl_algobase.h:64: /usr/include/c++/14/type_traits:666:33: error: 'nullptr_t' is not a member of 'std'; did you mean 'nullptr_t'? 666 | struct is_null_pointer<std::nullptr_t> | ^~~~~~~~~ /usr/lib/gcc/x86_64-linux-gnu/14/include/stddef.h:443:29: note: 'nullptr_t' declared here 443 | typedef decltype(nullptr) nullptr_t; | ^~~~~~~~~ /usr/include/c++/14/type_traits:666:42: error: template argument 1 is invalid 666 | struct is_null_pointer<std::nullptr_t> | ^ /usr/include/c++/14/type_traits:670:48: error: template argument 1 is invalid 670 | struct is_null_pointer<const std::nullptr_t> | ^ /usr/include/c++/14/type_traits:674:51: error: template argument 1 is invalid 674 | struct is_null_pointer<volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:678:57: error: template argument 1 is invalid 678 | struct is_null_pointer<const volatile std::nullptr_t> | ^ /usr/include/c++/14/type_traits:1429:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^~~~~~ /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/type_traits:1429:57: error: template argument 1 is invalid 1429 | : public integral_constant<std::size_t, alignof(_Tp)> | ^ /usr/include/c++/14/type_traits:1429:57: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1438:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1438 | : public integral_constant<std::size_t, 0> { }; | ^~~~~~ /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/type_traits:1438:46: error: template argument 1 is invalid 1438 | : public integral_constant<std::size_t, 0> { }; | ^ /usr/include/c++/14/type_traits:1438:46: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1440:26: error: 'std::size_t' has not been declared 1440 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:1441:21: error: '_Size' was not declared in this scope 1441 | struct rank<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:1441:27: error: template argument 1 is invalid 1441 | struct rank<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:1442:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /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/type_traits:1442:65: error: template argument 1 is invalid 1442 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1442:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:1446:37: error: 'size_t' is not a member of 'std'; did you mean 'size_t'? 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^~~~~~ /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/type_traits:1446:65: error: template argument 1 is invalid 1446 | : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; | ^ /usr/include/c++/14/type_traits:1446:65: note: invalid template non-type parameter /usr/include/c++/14/type_traits:2086:26: error: 'std::size_t' has not been declared 2086 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2087:30: error: '_Size' was not declared in this scope 2087 | struct remove_extent<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2087:36: error: template argument 1 is invalid 2087 | struct remove_extent<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2099:26: error: 'std::size_t' has not been declared 2099 | template<typename _Tp, std::size_t _Size> | ^~~ /usr/include/c++/14/type_traits:2100:35: error: '_Size' was not declared in this scope 2100 | struct remove_all_extents<_Tp[_Size]> | ^~~~~ /usr/include/c++/14/type_traits:2100:41: error: template argument 1 is invalid 2100 | struct remove_all_extents<_Tp[_Size]> | ^ /usr/include/c++/14/type_traits:2171:12: error: 'std::size_t' has not been declared 2171 | template<std::size_t _Len> | ^~~ /usr/include/c++/14/type_traits:2176:30: error: '_Len' was not declared in this scope 2176 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2194:12: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2194:30: error: 'std::size_t' has not been declared 2194 | template<std::size_t _Len, std::size_t _Align = | ^~~ /usr/include/c++/14/type_traits:2195:55: error: '_Len' was not declared in this scope 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^~~~ /usr/include/c++/14/type_traits:2195:59: error: template argument 1 is invalid 2195 | __alignof__(typename __aligned_storage_msa<_Len>::__type)> | ^ /usr/include/c++/14/type_traits:2202:30: error: '_Len' was not declared in this scope 2202 | unsigned char __data[_Len]; | ^~~~ /usr/include/c++/14/type_traits:2203:44: error: '_Align' was not declared in this scope 2203 | struct __attribute__((__aligned__((_Align)))) { } __align; | ^~~~~~ In file included from /usr/include/c++/14/bits/stl_tempbuf.h:59, from /usr/include/c++/14/bits/stl_algo.h:69, from /usr/include/c++/14/algorithm:61: /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) | ^~~~~~ /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__)); |
s641726489
p03718
C++
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define LB(a,x) lb(all(a),x)-a.begin() #define UB(a,x) ub(all(a),x)-a.begin() #define mod 1000000007 //#define mod 998244353 #define FS fixed<<setprecision(15) using namespace std; typedef long long ll; const double pi=3.141592653589793; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline void out(T a){ cout << a << '\n'; } void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;} //void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;} const ll INF=1e18; const int mx=200005; //ford-fulkerson //辺を表す構造体(行先,容量,逆辺(の番号)) struct edge{ll to,cap,rev;}; ll H,W; class FordFulkerson{ public: V<V<edge>> G;//グラフの隣接リスト V<bool> used;//DFSですでに調べたかのフラグ explicit FordFulkerson(ll max_V){ G.resize(max_V); used.resize(max_V); } //fromからtoへ容量capの辺をグラフに追加 void add_edge(ll from,ll to,ll cap){ G[from].push_back((edge){to,cap,(ll)G[to].size()}); G[to].push_back((edge){from,0LL,(ll)G[from].size()-1}); } //増加パスをDFSで探す ll dfs(ll v,ll t,ll f){ if(v==t) return f; used[v]=1; for(int i=0;i<(int)G[v].size();i++){ edge &e=G[v][i]; if(!used[e.to]&&e.cap>0){ ll d=dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } //sからtへの最大流を求める ll max_flow(ll s,ll t){ ll flow=0; while(true){ rep(i,(ll)used.size()) used[i]=0; ll f=dfs(s,t,INF); if(f==0) return flow; flow+=f; } } }; int main(){ cin.tie(0);ios::sync_with_stdio(false); cin>>H>>W; char a[H][W]; P S,T; rep(i,H) rep(j,W){ cin>>a[i][j]; if(a[i][j]=='S') S=make_pair(i,j); if(a[i][j]=='T') T=make_pair(i,j); } FordFulkerson ff(H+W+2); rep(i,H){ rep(j,W){ if(a[i][j]=='S'){ ff.add_edge(0,i+1,INF); ff.add_edge(0,H+j+1,INF); }else if(a[i][j]=='T'){ ff.add_edge(i+1,H+W+1,INF); ff.add_edge(H+j+1,H+W+1,INF); }else if(a[i][j]=='o'){ ff.add_edge(i+1,H+j+1,1LL); ff.add_edge(H+j+1,i+1,1LL); } } } ll ans=ff.max_flow(0,H+W+1); if(S/W==T/W||S%W==T%W) ans=-1; out(ans); }
a.cc: In function 'int main()': a.cc:113:9: error: no match for 'operator/' (operand types are 'P' {aka 'std::pair<long long int, long long int>'} and 'll' {aka 'long long int'}) 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ~^~ | | | | | ll {aka long long int} | P {aka std::pair<long long int, long long int>} In file included from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127, from a.cc:2: /usr/include/c++/14/complex:430:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const complex<_Tp>&)' 430 | operator/(const complex<_Tp>& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:430:5: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/complex:439:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const _Tp&)' 439 | operator/(const complex<_Tp>& __x, const _Tp& __y) | ^~~~~~~~ /usr/include/c++/14/complex:439:5: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/complex:448:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const _Tp&, const complex<_Tp>&)' 448 | operator/(const _Tp& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:448:5: note: template argument deduction/substitution failed: a.cc:113:10: note: mismatched types 'const std::complex<_Tp>' and 'll' {aka 'long long int'} 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ In file included from /usr/include/c++/14/valarray:605, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166: /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)' 408 | _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:408:5: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)' 408 | _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:408:5: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)' 408 | _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:408:5: note: template argument deduction/substitution failed: a.cc:113:10: note: mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'll' {aka 'long long int'} 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)' 408 | _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:408:5: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::_Expr<_Dom1, typename _Dom1::value_type>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)' 408 | _DEFINE_EXPR_BINARY_OPERATOR(/, struct std::__divides) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:408:5: note: template argument deduction/substitution failed: a.cc:113:10: note: mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'll' {aka 'long long int'} 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const valarray<_Tp>&, const valarray<_Tp>&)' 1199 | _DEFINE_BINARY_OPERATOR(/, __divides) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1199:1: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)' 1199 | _DEFINE_BINARY_OPERATOR(/, __divides) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1199:1: note: template argument deduction/substitution failed: a.cc:113:10: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::valarray<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/valarray:1199:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__divides, _Tp>::result_type> std::operator/(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)' 1199 | _DEFINE_BINARY_OPERATOR(/, __divides) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1199:1: note: template argument deduction/substitution failed: a.cc:113:10: note: mismatched types 'const std::valarray<_Tp>' and 'll' {aka 'long long int'} 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ a.cc:113:14: error: no match for 'operator/' (operand types are 'P' {aka 'std::pair<long long int, long long int>'} and 'll' {aka 'long long int'}) 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ~^~ | | | | | ll {aka long long int} | P {aka std::pair<long long int, long long int>} /usr/include/c++/14/complex:430:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const complex<_Tp>&)' 430 | operator/(const complex<_Tp>& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:430:5: note: template argument deduction/substitution failed: a.cc:113:15: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/complex:439:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const complex<_Tp>&, const _Tp&)' 439 | operator/(const complex<_Tp>& __x, const _Tp& __y) | ^~~~~~~~ /usr/include/c++/14/complex:439:5: note: template argument deduction/substitution failed: a.cc:113:15: note: 'P' {aka 'std::pair<long long int, long long int>'} is not derived from 'const std::complex<_Tp>' 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/complex:448:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator/(const _Tp&, const complex<_Tp>&)' 448 | operator/(const _Tp& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:448:5: note: template argument deduction/substitution failed: a.cc:113:15: note: mismatched types 'const std::complex<_Tp>' and 'll' {aka 'long long int'} 113 | if(S/W==T/W||S%W==T%W) ans=-1; | ^ /usr/include/c++/14/bits/valarray_after.h:408:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__divides, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__divides, typename _Dom1::value_type>::result_type> std::operator/(const _Expr<_Dom1, typename _Dom1::value_typ
s800939566
p03718
C++
#include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #include <functional> #include <bitset> #include <assert.h> #include <unordered_map> #include <fstream> #include <ctime> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 510000; ll dy[8] = {1,-1,0,0,1,-1,1,-1}; ll dx[8] = {0,0,1,-1,1,-1,-1,1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ rep(i,a.size()) cout << a[i] << " "; cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";} template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; struct Dinic{ struct edge{ ll to, cap, rev; }; vector<vector<edge>> G; vector<int> level, itr; ll n; const ll INF = 1<<30; Dinic(ll n) : n(n){ G.resize(n); level.resize(n); itr.resize(n); } void add_edge(ll from, ll to, ll cap){ G[from].push_back({to,cap,(ll)G[to].size()}); G[to].push_back({from,0,(ll)G[from].size()-1}); } void bfs(int s){ fill(level.begin(), level.end(), -1); queue<int> q; level[s] = 0; q.push(s); while(!q.empty()){ int u = q.front(); q.pop(); for(auto &e : G[u]){ if(e.cap > 0 && level[e.to] < 0){ level[e.to] = level[u] + 1; q.push(e.to); } } } } ll dfs(int u, int t, ll f){ if(u == t) return f; for(int &i = itr[u]; i < G[u].size(); i++){ edge &e = G[u][i]; if(e.cap > 0 && level[u] < level[e.to]){ ll d = dfs(e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(ll s, ll t){ ll flow = 0; while(1){ bfs(s); if(level[t] < 0) return flow; fill(itr.begin(), itr.end(), 0); ll f; while((f = dfs(s, t, INF)) > 0){ flow += f; } } } }; char a[101][101]; int main(){ ll h,w; cin >> h >> w; rep(i,h) rep(j,w) cin >> a[i][j]; FF flow(h+w+2); P s,t; rep(i,h){ rep(j,w){ if(a[i][j] == '.') continue; if(a[i][j] == 'S') s = P(i,j); if(a[i][j] == 'T') t = P(i,j); else{ flow.add_edge(i, h+j, 1); flow.add_edge(h+j, i, 1); } } } flow.add_edge(h+w, s.first, inf); flow.add_edge(h+w, h+s.second, inf); flow.add_edge(t.first, h+w+1, inf); flow.add_edge(h+t.second, h+w+1, inf); int ans = flow.max_flow(h+w, h+w+1); if(ans >= h+w) puts("-1"); else cout << ans << "\n"; }
a.cc: In function 'int main()': a.cc:136:9: error: 'FF' was not declared in this scope 136 | FF flow(h+w+2); | ^~ a.cc:144:33: error: 'flow' was not declared in this scope 144 | flow.add_edge(i, h+j, 1); | ^~~~ a.cc:149:9: error: 'flow' was not declared in this scope 149 | flow.add_edge(h+w, s.first, inf); | ^~~~
s788918829
p03718
C++
#include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include <unordered_map> #include <map> #include <set> #include <algorithm> #include <queue> #include <stack> #include <functional> #include <bitset> #include <assert.h> #include <unordered_map> #include <fstream> #include <ctime> using namespace std; typedef long long ll; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<char> vc; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<double> vd; typedef pair<ll,ll> P; typedef pair<int,int> pii; typedef vector<P> vpl; typedef tuple<ll,ll,ll> tapu; #define rep(i,n) for(int i=0; i<(n); i++) #define REP(i,a,b) for(int i=(a); i<(b); i++) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int inf = 1<<30; const ll linf = 1LL<<62; const int MAX = 510000; ll dy[8] = {1,-1,0,0,1,-1,1,-1}; ll dx[8] = {0,0,1,-1,1,-1,-1,1}; const double pi = acos(-1); const double eps = 1e-7; template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){ if(a>b){ a = b; return true; } else return false; } template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){ if(a<b){ a = b; return true; } else return false; } template<typename T> inline void print(T &a){ rep(i,a.size()) cout << a[i] << " "; cout << "\n"; } template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";} template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){ cout << a << " " << b << " " << c << "\n"; } ll pcount(ll x) {return __builtin_popcountll(x);} const int mod = 1e9 + 7; //const int mod = 998244353; struct Dinic{ struct edge{ ll to, cap, rev; }; vector<vector<edge>> G; vector<int> level, itr; ll n; const ll INF = 1<<30; Dinic(ll n) : n(n){ G.resize(n); level.resize(n,0); itr.resize(n,0); } void add_edge(ll from, ll to, ll cap){ G[from].push_back({to,cap,(ll)G[to].size()}); G[to].push_back({from,0,(ll)G[from].size()-1}); } void bfs(int s){ fill(level.begin(), level.end(), -1); queue<int> q; level[s] = 0; while(!q.empty()){ int u = q.front(); q.pop(); for(auto &e : G[u]){ if(e.cap > 0 && level[e.to] < 0){ level[e.to] = level[u] + 1; q.push(e.to); } } } } int dfs(int u, int t, ll f){ if(u == t) return f; for(int &i = itr[u]; i < G[u].size(); i++){ edge &e = G[u][i]; if(e.cap > 0 && level[v] < level[e.to]){ int d = dfs(e.to, t, min(f, e.cap)); if(d > 0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } ll max_flow(ll s, ll t){ ll flow = 0; while(1){ bfs(s); if(level[t] < 0) return flow; fill(itr.begin(), itr.end(), 0); ll f; while((f = dfs(s, t, inf)) > 0){ flow += f; } } } }; char a[101][101]; int main(){ ll h,w; cin >> h >> w; rep(i,h) rep(j,w) cin >> a[i][j]; Dinic flow(h*w*2); ll s,t; rep(i,h){ rep(j,w){ if(a[i][j] == '.') continue; if(a[i][j] == 'S') s = i*w+j + h*w; if(a[i][j] == 'T') t = i*w+j; if(a[i][j] == 'o') flow.add_edge(i*w+j, h*w + i*w+j, 1); rep(k,h){ if(i == k || a[k][j] == 'S' || a[k][j] == '.') continue; flow.add_edge(h*w + i*w+j, k*w+j, inf); } rep(k,w){ if(j == k || a[i][k] == 'S' || a[i][k] == '.') continue; flow.add_edge(h*w + i*w+j, i*w+k, inf); } } } int ans = flow.max_flow(s,t); if(ans > h*w) puts("-1"); else cout << ans << "\n"; }
a.cc: In member function 'int Dinic::dfs(int, int, ll)': a.cc:104:47: error: 'v' was not declared in this scope; did you mean 'vs'? 104 | if(e.cap > 0 && level[v] < level[e.to]){ | ^ | vs
s723271457
p03718
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef std::pair<int, int> ii; typedef tuple<int,int,int> i3; typedef std::pair<int, ii> iii; typedef std::vector<int> vi; typedef std::vector<vi> vvi; typedef std::vector<ii> vii; typedef std::vector<iii> viii; const int INF = 1001001000; const ll mod = 1e9 + 7; const ld pi=acos(-1); #define pb(a) push_back(a) #define m0(x,n) memset(x,n,sizeof(x)) #define print(x) cout<<x<<endl; #define pe(x) cout<<x<<" "; #define lb(v,n) lower_bound(v.begin(), v.end(), n); // greater than or equal #define ub(v,n) upper_bound(v.begin(), v.end(), n); // greater than #define all(x) (x).begin(), (x).end(); #define fi first; #define se second; #define endl '\n'; #define loop(i,n) for(int i=0;i<(n);i++); #define FOR(i, m, n) for(int i = m; i < n; i++); int h,w; string a[101]; struct flow_network { int n, s, t, *par, **c, **f; vi *adj; flow_network(int n, int s, int t) : n(n), s(s), t(t) { adj = new std::vector<int>[n]; par = new int[n]; c = new int*[n]; f = new int*[n]; for (int i = 0; i < n; ++i) { c[i] = new int[n]; f[i] = new int[n]; for (int j = 0; j < n; ++j) c[i][j] = f[i][j] = 0; } } void add_edge(int u, int v, int w) { adj[u].push_back(v); adj[v].push_back(u); c[u][v] += w; } int res(int i, int j) { return c[i][j] - f[i][j]; } bool bfs() { std::queue<int> q; q.push(this->s); while (!q.empty()) { int u = q.front(); q.pop(); for (int v : adj[u]) { if (res(u, v) > 0 and par[v] == -1) { par[v] = u; if (v == this->t) return true; q.push(v); } } } return false; } bool aug_path() { for (int u = 0; u < n; ++u) par[u] = -1; par[s] = s; return bfs(); } int calc_max_flow() { int ans = 0; while (aug_path()) { int flow = INF; for (int u = t; u != s; u = par[u]) flow = std::min(flow, res(par[u], u)); for (int u = t; u != s; u = par[u]) f[par[u]][u] += flow, f[u][par[u]] -= flow; ans += flow; } return ans; } }; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> h >> w; for (int i=0; i<h; i++) cin >> a[i]; ii t,s; flow_network G(h+w+3,0,h+w+2); for (int i=1; i<=h; i++){ for (int j=1; j<=w; j++){ if (a[i-1][j-1]=='S') {G.add_edge(0,i,INF); G.add_edge(0,j+h,INF);} if (a[i-1][j-1]=='T') {G.add_edge(i,h+w+2,INF); G.add_edge(j+h,h+w+2,INF);} if (a[i-1][j-1]=='o') {G.add_edge(i,j+h,1); G.add_edge(j+h,i,1);} } } if (s.first==t.first or s.second==t.second) cout<<-1<<endl; else cout<<G.calc_max_flow(); }
a.cc: In function 'int main()': a.cc:106:3: error: 'else' without a previous 'if' 106 | else cout<<G.calc_max_flow(); | ^~~~
s529141908
p03718
C++
#pragma GCC optimize(2) #include<bits/stdc++.h> #define ll long long #define maxn 100005 #define inf 1e9 #define pb push_back #define rep(i,a,b) for(int i=a;i<=b;i++) #define per(i,a,b) for(int i=a;i>=b;i--) using namespace std; inline int read() { int x=0,w=1; char c=getchar(); while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();} while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();} return w==1?x:-x; } char ch[maxn][maxn]; struct node{int from,to,cap,flow;}; vector <node> edges; vector <int> mp[maxn]; int n,m,s,t,d[maxn],cur[maxn],F; bool vis[maxn]; queue <int> que; inline void A(int u,int v,int w) { //cout<<u<<" "<<v<<" "<<w<<endl; edges.push_back((node){u,v,w,0}); edges.push_back((node){v,u,0,0}); int pp=edges.size(); mp[u].push_back(pp-2); mp[v].push_back(pp-1); } inline bool bfs() { for(int i=0;i<=2*n*m;i++) d[i]=inf,vis[i]=0; d[s]=0; vis[s]=1; que.push(s); while(!que.empty()) { int u=que.front(); que.pop(); for(int i=0;i<mp[u].size();i++) { node v=edges[mp[u][i]]; if(v.cap-v.flow>0&&!vis[v.to]) { d[v.to]=d[u]+1; vis[v.to]=1; que.push(v.to); } } } if(vis[t]) return true; return false; } inline int dfs(int u,int w) { int flow=0,r=0; if(u==t||w==0) return w; for(int i=0;i<mp[u].size();i++) { node &v=edges[mp[u][i]]; if(d[v.to]==d[u]+1&&(r=dfs(v.to,min(v.cap-v.flow,w)))>0) { flow+=r; edges[mp[u][i]].flow+=r; edges[mp[u][i]^1].flow-=r; w-=r; if(w==0) break; } } return flow; } inline int max_flow() { int ff=0; while(bfs()) { memset(cur,0,sizeof(cur)); ff+=dfs(s,inf); } return ff; } inline int X(int x,int y){return (x-1)*m+y;} inline void jud(int x,int y) { for(int i=1;i<=n;i++) if(ch[i][y]=='T') F=1; for(int i=1;i<=m;i++) if(ch[x][i]=='T') F=1; } inline void a1(int x,int y) { for(int i=1;i<=n;i++) if(ch[i][y]=='o') A(s,X(i,y),1); for(int i=1;i<=m;i++) if(ch[x][i]=='o') A(s,X(x,i),1); } inline void a2(int x,int y) { for(int i=1;i<=n;i++) if(ch[i][y]=='o') A(X(i,y),t,1); for(int i=1;i<=m;i++) if(ch[x][i]=='o') A(X(x,i),t,1); } inline void a3(int x,int y) { for(int i=1;i<=n;i++) if(ch[i][y]=='o'&&i!=x) A(X(x,y)+n*m,X(i,y),1); for(int i=1;i<=m;i++) if(ch[x][i]=='o'&&i!=y) A(X(x,y)+n*m,X(x,i),1); } int main() { n=read(); m=read(); rep(i,1,n) scanf("%s",ch[i]+1); rep(i,1,n) rep(j,1,m) { if(ch[i][j]=='.') continue; if(ch[i][j]=='S') s=X(i,j),jud(i,j),a1(i,j); else if(ch[i][j]=='T') t=X(i,j)+n*m,a2(i,j); } rep(i,1,n) rep(j,1,m) if(ch[i][j]=='o') a3(i,j); rep(i,1,n) rep(j,1,m) if(ch[i][j]!='S'&&ch[i][j]!='T') A(X(i,j),X(i,j)+n*m,1); if(F) return puts("-1"),0; printf("%d\n",max_flow()); return 0; }
/tmp/ccAmseN1.o: in function `__tcf_0': a.cc:(.text+0x10): relocation truncated to fit: R_X86_64_PC32 against symbol `mp' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text+0x17): relocation truncated to fit: R_X86_64_PC32 against symbol `mp' defined in .bss section in /tmp/ccAmseN1.o /tmp/ccAmseN1.o: in function `__static_initialization_and_destruction_0()': a.cc:(.text+0x3e): relocation truncated to fit: R_X86_64_PC32 against symbol `edges' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text+0x57): relocation truncated to fit: R_X86_64_PC32 against symbol `edges' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text+0x70): relocation truncated to fit: R_X86_64_PC32 against symbol `mp' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text+0xb4): relocation truncated to fit: R_X86_64_PC32 against symbol `que' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text+0xcd): relocation truncated to fit: R_X86_64_PC32 against symbol `que' defined in .bss section in /tmp/ccAmseN1.o /tmp/ccAmseN1.o: in function `A(int, int, int)': a.cc:(.text._Z1Aiii[_Z1Aiii]+0x7): relocation truncated to fit: R_X86_64_PC32 against symbol `edges' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text._Z1Aiii[_Z1Aiii]+0x6c): relocation truncated to fit: R_X86_64_PC32 against symbol `mp' defined in .bss section in /tmp/ccAmseN1.o /tmp/ccAmseN1.o: in function `bfs()': a.cc:(.text._Z3bfsv[_Z3bfsv]+0x10): relocation truncated to fit: R_X86_64_PC32 against symbol `n' defined in .bss section in /tmp/ccAmseN1.o a.cc:(.text._Z3bfsv[_Z3bfsv]+0x17): additional relocation overflows omitted from the output collect2: error: ld returned 1 exit status
s105559237
p03718
C++
#include <iostream> #include <iomanip> #include <vector> #include <algorithm> #include <stack> #include <queue> #include <limits.h> #include <cmath> #include <map> using namespace std; using ll=long long; #define int long long const int INF=INT_MAX/3; struct edge{ int to,cap,rev; }; vector<edge> G[210]; vector<bool> used(210); void add_edge(int from,int to,int cap){ G[from].emplace_back((edge){to,cap,(int)G[to].size()}); G[to].emplace_back((edge){from,0,(int)G[from].size()-1}); } int dfs(int v,int t,int f){ if(v==t)return f; used[v]=true; for(int i=0;i<G[v].size();i++){ edge &e=G[v][i]; if(!used[e.to]&&e.cap>0){ int d=dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } int max_flow(int s,int t){ int flow=0; while(1){ fill(used.begin(),used.end(),false); int f=dfs(s,t,INF); if(f==0)return flow; flow+=f; } } int main(){ int h,w; cin>>h>>w; vector<vector<char>> a(h,vector<char>(w)); pair<int,int> s,t; for(int i=0;i<h;i++){ for(int j=0;j<w;j++){ cin>>a[i][j]; if(a[i][j]=='S'){ add_edge(0,i+1,INF); add_edge(0,h+j+1,INF); s.first=i,s.second=j; } if(a[i][j]=='T'){ add_edge(i+1,h+w+1,INF); add_edge(h+j+1,h+w+1,INF); t.first=i,t.second=j; } if(a[i][j]=='o'){ add_edge(i+1,h+j+1,1); add_edge(h+j+1,i+1,1); } } } int ret=max_flow(0,h+w+1); if(ret==INF)ret=-1; cout<<ret<<endl; }
cc1plus: error: '::main' must return 'int'
s639041070
p03718
C++
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <cstdio> #include <cmath> #include <cassert> #include <limits> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; /*-*/ template <typename T = lnt, T INF = std::numeric_limits<T>::max()> struct Dinic { struct Edge { int a,b; T c,f; Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {} }; int n,m; std::vector<Edge> E; std::vector<std::vector<int> > G,Gf; Dinic(int n) : n(n),m(0),G(n),Gf(n) {} void add_edge(int i, int j, int c) { E.emplace_back(i,j,c); E.emplace_back(j,i,0); G[i].emplace_back(m++); G[j].emplace_back(m++); } bool bfs(int s, int t) { Gf.assign(n,std::vector<int>()jj); std::queue<int> que; que.emplace(s); std::vector<int> dist(n,-1); dist[s]=0; while(!que.empty()) { int i=que.front(); que.pop(); for(int to:G[i]) { if(dist[E[to].b]!=-1 || E[to].c==E[to].f) continue; dist[E[to].b]=dist[E[to].a]+1; que.emplace(E[to].b); } } if(dist[t]==-1) return false; for(int i=0;i<m;i++) { if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f) continue; Gf[E[i].a].emplace_back(i); } return true; } T dfs(int i, T a_f, const int& t) { if(i==t || a_f==0) { return a_f; } T v_f=0; for(int to:Gf[i]) { T f=dfs(E[to].b,std::min(a_f-v_f,E[to].c-E[to].f),t); E[to].f+=f; E[to^1].f-=f; v_f+=f; if(a_f==v_f) break; } return v_f; } T flow(int s, int t) { T max_flow=0; while(bfs(s,t)) { T f = dfs(s,INF,t); if(f==0) break; max_flow+=f; } return max_flow; } }; int main() { int h,w; std::cin >> h >> w; std::vector<std::string> g(h); rep(i,h) std::cin >> g[i]; std::vector<std::vector<int> > X(h),Y(w); int sx,sy,tx,ty; rep(i,h) { rep(j,w) { if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') { if(g[i][j]=='S') { sx=i; sy=j; } if(g[i][j]=='T') { tx=i; ty=j; } X[i].emplace_back(j); Y[j].emplace_back(i); } } } if(sx==tx||sy==ty) { print(-1); return 0; } auto enc = [&] (int i, int j) { return i*w+j; }; debug(sx,sy,tx,ty); Dinic<int> flow(2*h*w); rep(i,h) { for(auto y1:X[i]) for(auto y2:X[i]) { if(y1==y2) continue; flow.add_edge(enc(i,y1),h*w+enc(i,y2),1); } } rep(i,w) { for(auto x1:Y[i]) for(auto x2:Y[i]) { if(x1==x2) continue; flow.add_edge(enc(x1,i),h*w+enc(x2,i),1); } } rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1); print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w)); }
a.cc: In member function 'bool Dinic<T, INF>::bfs(int, int)': a.cc:52:47: error: expected ')' before 'jj' 52 | Gf.assign(n,std::vector<int>()jj); | ^~ a.cc:52:26: note: to match this '(' 52 | Gf.assign(n,std::vector<int>()jj); | ^
s805152943
p03718
C++
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <cstdio> #include <cmath> #include <cassert> #include <limits> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; /*-*/ template <typename T = lnt, T INF = std::numeric_limits<T>::max()> struct Dinic { struct Edge { int a,b; T c,f; Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {} }; int n,m; std::vector<Edge> E; std::vector<std::vector<int> > G,Gf; Dinic(int n) : n(n),m(0),G(n),Gf(n) {} void add_edge(int i, int j, int c) { E.emplace_back(i,j,c); E.emplace_back(j,i,0); G[i].emplace_back(m++); G[j].emplace_back(m++); } bool bfs(int s, int t) { Gf.assign(n,std::vector<int>()); std::queue<int> que; que.emplace(s); std::vector<int> dist(n,-1); dist[s]=0; while(!que.empty()) { int i=que.front(); que.pop(); for(int to:G[i]) { if(dist[E[to].b]!=-1 || E[to].c==E[to].f) continue; dist[E[to].b]=dist[E[to].a]+1; que.emplace(E[to].b); } } if(dist[t]==-1) return false; for(int i=0;i<m;i++) { if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f) continue; Gf[E[i].a].emplace_back(i); } return true; } T dfs(int i, T a_f, const int& t) { if(i==t || a_f==0) { return a_f; } T v_f=0; for(int to:Gf[i]) { if(max_flow==0) break; T f=dfs(E[to].b,std::min(a_f-v_f,E[to].c-E[to].f),t); E[to].f+=f; E[to^1].f-=f; v_f+=f; } return v_f; } T flow(int s, int t) { T max_flow=0; while(bfs(s,t)) { T f = dfs(s,INF,t); if(f==0) break; max_flow+=f; } return max_flow; } }; int main() { int h,w; std::cin >> h >> w; std::vector<std::string> g(h); rep(i,h) std::cin >> g[i]; std::vector<std::vector<int> > X(h),Y(w); int sx,sy,tx,ty; rep(i,h) { rep(j,w) { if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') { if(g[i][j]=='S') { sx=i; sy=j; } if(g[i][j]=='T') { tx=i; ty=j; } X[i].emplace_back(j); Y[j].emplace_back(i); } } } if(sx==tx||sy==ty) { print(-1); return 0; } auto enc = [&] (int i, int j) { return i*w+j; }; debug(sx,sy,tx,ty); Dinic<int> flow(2*h*w); rep(i,h) { for(auto y1:X[i]) for(auto y2:X[i]) { if(y1==y2) continue; flow.add_edge(enc(i,y1),h*w+enc(i,y2),1); } } rep(i,w) { for(auto x1:Y[i]) for(auto x2:Y[i]) { if(x1==x2) continue; flow.add_edge(enc(x1,i),h*w+enc(x2,i),1); } } rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1); print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w)); }
a.cc: In member function 'T Dinic<T, INF>::dfs(int, T, const int&)': a.cc:76:28: error: 'max_flow' was not declared in this scope 76 | if(max_flow==0) break; | ^~~~~~~~
s688007333
p03718
C++
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <cstdio> #include <cmath> #include <cassert> #include <limits> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; /*-*/ template <typename T = lnt, T INF = std::numeric_limits<T>::max()> struct Dinic { struct Edge { int a,b; T c,f; Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {} }; int n,m; std::vector<Edge> E; std::vector<std::vector<int> > G,Gf; Dinic(int n) : n(n),m(0),G(n),Gf(n) {} void add_edge(int i, int j, int c) { E.emplace_back(i,j,c); E.emplace_back(j,i,0); G[i].emplace_back(m++); G[j].emplace_back(m++); } bool bfs(int s, int t) { Gf.assign(n); std::queue<int> que; que.emplace(s); std::vector<int> dist(n,-1); dist[s]=0; while(!que.empty()) { int i=que.front(); que.pop(); for(int to:G[i]) { if(dist[E[to].b]!=-1 || E[to].c==E[to].f) continue; dist[E[to].b]=dist[E[to].a]+1; que.emplace(E[to].b); } } if(dist[t]==-1) return false; for(int i=0;i<m;i++) { if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f) continue; Gf[E[i].a].emplace_back(i); } return true; } T dfs(int i, T a_f, const int& t) { if(i==t || a_f==0) { return a_f; } T v_f=0; for(int to:Gf[i]) { if(max_flow==0) break; T f=dfs(E[to].b,std::min(a_f-v_f,E[to].c-E[to].f),t); E[to].f+=f; E[to^1].f-=f; v_f+=f; } return v_f; } T flow(int s, int t) { T max_flow=0; while(bfs(s,t)) { T f = dfs(s,INF,t); if(f==0) break; max_flow+=f; } return max_flow; } }; int main() { int h,w; std::cin >> h >> w; std::vector<std::string> g(h); rep(i,h) std::cin >> g[i]; std::vector<std::vector<int> > X(h),Y(w); int sx,sy,tx,ty; rep(i,h) { rep(j,w) { if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') { if(g[i][j]=='S') { sx=i; sy=j; } if(g[i][j]=='T') { tx=i; ty=j; } X[i].emplace_back(j); Y[j].emplace_back(i); } } } if(sx==tx||sy==ty) { print(-1); return 0; } auto enc = [&] (int i, int j) { return i*w+j; }; debug(sx,sy,tx,ty); Dinic<int> flow(2*h*w); rep(i,h) { for(auto y1:X[i]) for(auto y2:X[i]) { if(y1==y2) continue; flow.add_edge(enc(i,y1),h*w+enc(i,y2),1); } } rep(i,w) { for(auto x1:Y[i]) for(auto x2:Y[i]) { if(x1==x2) continue; flow.add_edge(enc(x1,i),h*w+enc(x2,i),1); } } rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1); print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w)); }
a.cc: In member function 'bool Dinic<T, INF>::bfs(int, int)': a.cc:52:26: error: no matching function for call to 'std::vector<std::vector<int> >::assign(int&)' 52 | Gf.assign(n); | ~~~~~~~~~^~~ In file included from /usr/include/c++/14/vector:66, from a.cc:4: /usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]' 828 | assign(_InputIterator __first, _InputIterator __last) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; size_type = long unsigned int; value_type = std::vector<int>]' 808 | assign(size_type __n, const value_type& __val) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]' 855 | assign(initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:855:43: note: no known conversion for argument 1 from 'int' to 'std::initializer_list<std::vector<int> >' 855 | assign(initializer_list<value_type> __l) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~ a.cc: In member function 'T Dinic<T, INF>::dfs(int, T, const int&)': a.cc:76:28: error: 'max_flow' was not declared in this scope 76 | if(max_flow==0) break; | ^~~~~~~~
s870866535
p03718
C++
#include <iostream> #include <algorithm> #include <numeric> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <deque> #include <stack> #include <iomanip> #include <functional> #include <bitset> #include <cstdio> #include <cmath> #include <cassert> #include <limits> #ifdef DEBUG #include "library/Utility/debug.cpp" #else #define debug(...) #endif #define rep(i,n) for(int i=0;i<(n);++i) #define EL '\n' #define print(i) std::cout << (i) << '\n' #define all(v) (v).begin(), (v).end() using lnt = long long; constexpr lnt INF = 2e18; /*-*/ template <typename T = lnt> struct Dinic { struct Edge { int a,b; T c,f; Edge(int a, int b, T c) : a(a),b(b),c(c),f(0) {} }; const T INF; int n,m=0; std::vector<std::vector<int> > G,Gf; std::vector<Edge> E; Dinic(int n) : n(n),INF(std::numeric_limits<T>::max()),G(n),Gf(n) {} void add_edge(int i, int j, int c) { E.emplace_back(i,j,c); E.emplace_back(j,i,0); G[i].emplace_back(m); G[j].emplace_back(m|1); m+=2; } bool bfs(int s, int t) { Gf.assign(n,0); std::queue<int> que; que.emplace(s); std::vector<int> dist(n,INF); dist[s]=0; while(!que.empty()) { int i=que.front(); que.pop(); for(int to:G[i]) { if(dist[E[to].b]!=INF || E[to].c==E[to].f) continue; dist[E[to].b]=dist[E[to].a]+1; que.emplace(E[to].b); } } if(dist[t]==INF) return true; for(int i=0;i<m;i++) { if(dist[E[i].a]+1!=dist[E[i].b] || E[i].c==E[i].f) continue; Gf[E[i].a].emplace_back(i); } return false; } T dfs(int i, T max_flow, const int& t) { if(i==t || max_flow==0) { return max_flow; } T v_flow=0; for(int to:Gf[i]) { if(max_flow==0) break; T f=dfs(E[to].b,std::min(max_flow,E[to].c-E[to].f),t); if(f>0) { E[to].f+=f; E[to^1].f-=f; v_flow+=f; max_flow-=f; } } return v_flow; } T flow(int s, int t) { T max_flow=0; while(true) { if(bfs(s,t)) break; T f = dfs(s,INF,t); if(f==0) break; max_flow+=f; } return max_flow; } }; int main() { int h,w; std::cin >> h >> w; std::vector<std::string> g(h); rep(i,h) std::cin >> g[i]; std::vector<std::vector<int> > X(h),Y(w); int sx,sy,tx,ty; rep(i,h) { rep(j,w) { if(g[i][j]=='o'||g[i][j]=='S'||g[i][j]=='T') { if(g[i][j]=='S') { sx=i; sy=j; } if(g[i][j]=='T') { tx=i; ty=j; } X[i].emplace_back(j); Y[j].emplace_back(i); } } } if(sx==tx||sy==ty) { print(-1); return 0; } auto enc = [&] (int i, int j) { return i*w+j; }; debug(sx,sy,tx,ty); Dinic<int> flow(2*h*w); rep(i,h) { for(auto y1:X[i]) for(auto y2:X[i]) { if(y1==y2) continue; flow.add_edge(enc(i,y1),h*w+enc(i,y2),1); } } rep(i,w) { for(auto x1:Y[i]) for(auto x2:Y[i]) { if(x1==x2) continue; flow.add_edge(enc(x1,i),h*w+enc(x2,i),1); } } rep(i,h) rep(j,w) flow.add_edge(enc(i,j)+h*w,enc(i,j),1); print(flow.flow(enc(sx,sy),enc(tx,ty)+h*w)); }
a.cc: In member function 'bool Dinic<T>::bfs(int, int)': a.cc:55:26: error: no matching function for call to 'std::vector<std::vector<int> >::assign(int&, int)' 55 | Gf.assign(n,0); | ~~~~~~~~~^~~~~ In file included from /usr/include/c++/14/vector:66, from a.cc:4: /usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]' 828 | assign(_InputIterator __first, _InputIterator __last) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:828:9: note: template argument deduction/substitution failed: In file included from /usr/include/c++/14/bits/stl_iterator_base_funcs.h:66, 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_types.h: In substitution of 'template<class _InIter> using std::_RequireInputIter = std::__enable_if_t<((bool)std::is_convertible<typename std::iterator_traits< <template-parameter-1-1> >::iterator_category, std::input_iterator_tag>::value)> [with _InIter = int]': /usr/include/c++/14/bits/stl_vector.h:825:9: required from here 825 | typename = std::_RequireInputIter<_InputIterator>> | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator_base_types.h:252:57: error: no type named 'iterator_category' in 'struct std::iterator_traits<int>' 252 | input_iterator_tag>::value>; | ^~~~~ /usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; size_type = long unsigned int; value_type = std::vector<int>]' 808 | assign(size_type __n, const value_type& __val) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:808:47: note: no known conversion for argument 2 from 'int' to 'const std::vector<std::vector<int> >::value_type&' {aka 'const std::vector<int>&'} 808 | assign(size_type __n, const value_type& __val) | ~~~~~~~~~~~~~~~~~~^~~~~ /usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >]' 855 | assign(initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate expects 1 argument, 2 provided
s820329381
p03718
C++
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); ++i) #define reps(i,n) for (int i = 1; i <= (int)(n); ++i) #define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i) #define repds(i,n) for (int i = (int)(n); i > 0; --i) #define loop(i,x,n) for (int i = (int)(x); i < (n); ++i) #define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i) #define loopd(i,x,n) for (int i = (int)(x); i > (n); --i) #define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i) #define itrep(i,a) for (auto i = begin(a); i != end(a); ++i) #define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i) #define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x) using namespace std; using ll = long long; using ld = long double; constexpr ll inf = static_cast<ll>(1e18); constexpr int iinf = static_cast<int>(1e9); constexpr double dinf = 1e10; constexpr ld ldinf = 1e18; ll mod = static_cast<ll>(1e9 + 7); template<class T> constexpr int sz(const T& a) { return (int)a.size(); } template<class T> constexpr T pow2(const T a) { return a * a; } template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); } template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); } template<class A, int N, class T> void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } template<class T, typename T INF> class Dinic { public: Dinic(int n) :g(n), level(n), iter(n) {} void add_edge(int from, int to, T cap) { g[from].emplace_back(to, cap, (int)g[to].size()); g[to].emplace_back(from, 0, (int)g[from].size() - 1); } T max_flow(int s, int t) { T flow = 0; while (true) { bfs(s); if (level[t] < 0) return flow; std::fill(iter.begin(), iter.end(), 0); T f; while ((f = dfs(s, t, INF)) > 0) flow += f; } } private: void bfs(int s) { std::fill(level.begin(), level.end(), -1); std::queue<int> que; level[s] = 0; que.push(s); while (!que.empty()) { auto v = que.front(); que.pop(); for (int i = 0; i < (int)g[v].size(); ++i) { auto& e = g[v][i]; if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; que.push(e.to); } } } } T dfs(int v, int t, T f) { if (v == t) return f; for (int& i = iter[v]; i < (int)g[v].size(); ++i) { auto& e = g[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { auto d = dfs(e.to, t, std::min<T>(f, e.cap)); if (d > 0) { e.cap -= d; g[e.to][e.rev].cap += d; return d; } } } return 0; } struct Edge { int to, rev; T cap; Edge(int t, T c, int r) :to(t), cap(c), rev(r) {} }; std::vector<std::vector<Edge>> g; std::vector<int> level; std::vector<int> iter; }; int h, w; char a[105][105]; void solve() { cin >> h >> w; rep(i, h) rep(j, w) cin >> a[i][j]; Dinic<int, iinf> dinic(h + w + 2); rep(i, h) rep(j, w) { if (a[i][j] == 'S') { dinic.add_edge(0, i + 1, iinf); dinic.add_edge(0, h + j + 1, iinf); } else if (a[i][j] == 'T') { dinic.add_edge(i + 1, h + w + 1, iinf); dinic.add_edge(h + j + 1, h + w + 1, iinf); } else if (a[i][j] == 'o') { dinic.add_edge(i + 1, h + j + 1, 1); dinic.add_edge(h + j + 1, i + 1, 1); } } auto ans = dinic.max_flow(0, h + w + 1); if (ans == iinf) cout << -1 << endl; else cout << ans << endl; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }
a.cc:29:28: error: expected nested-name-specifier before 'T' 29 | template<class T, typename T INF> | ^ a.cc:29:30: error: expected '>' before 'INF' 29 | template<class T, typename T INF> | ^~~ a.cc: In function 'void solve()': a.cc:97:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 97 | dinic.add_edge(0, i + 1, iinf); | ^~~~~~~~ a.cc:98:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 98 | dinic.add_edge(0, h + j + 1, iinf); | ^~~~~~~~ a.cc:101:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 101 | dinic.add_edge(i + 1, h + w + 1, iinf); | ^~~~~~~~ a.cc:102:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 102 | dinic.add_edge(h + j + 1, h + w + 1, iinf); | ^~~~~~~~ a.cc:105:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 105 | dinic.add_edge(i + 1, h + j + 1, 1); | ^~~~~~~~ a.cc:106:19: error: request for member 'add_edge' in 'dinic', which is of non-class type 'int' 106 | dinic.add_edge(h + j + 1, i + 1, 1); | ^~~~~~~~ a.cc:109:22: error: request for member 'max_flow' in 'dinic', which is of non-class type 'int' 109 | auto ans = dinic.max_flow(0, h + w + 1); | ^~~~~~~~
s556470923
p03718
C++
#include <bits/stdc++.h> using namespace std; struct Template_MPM{ struct FlowEdge{ int v, u; long long cap, flow; FlowEdge(){} FlowEdge(int _v, int _u, long long _cap, long long _flow) : v(_v), u(_u), cap(_cap), flow(_flow){} FlowEdge(int _v, int _u, long long _cap) : v(_v), u(_u), cap(_cap), flow(0ll){} }; const long long flow_inf = 1e18; vector<FlowEdge> edges; vector<char> alive; vector<long long> pin, pout; vector<list<int> > in, out; vector<vector<int> > adj; vector<long long> ex; int n, m = 0; int s, t; vector<int> level; vector<int> q; int qh, qt; void resize(int _n){ n = _n; ex.resize(n); q.resize(n); pin.resize(n); pout.resize(n); adj.resize(n); level.resize(n); in.resize(n); out.resize(n); } TEmplate_MPM(){} void init(int _n, int _s, int _t){resize(_n); s = _s; t = _t;} void add_edge(int v, int u, long long cap){ edges.push_back(FlowEdge(v, u, cap)); edges.push_back(FlowEdge(u, v, cap)); adj[v].push_back(m); adj[u].push_back(m + 1); m += 2; } bool bfs(){ while(qh < qt){ int v = q[qh++]; for(int id : adj[v]){ if(edges[id].cap - edges[id].flow < 1)continue; if(level[edges[id].u] != -1)continue; level[edges[id].u] = level[v] + 1; q[qt++] = edges[id].u; } } return level[t] != -1; } long long pot(int v){ return min(pin[v], pout[v]); } void remove_node(int v){ for(int i : in[v]){ int u = edges[i].v; auto it = find(out[u].begin(), out[u].end(), i); out[u].erase(it); pout[u] -= edges[i].cap - edges[i].flow; } for(int i : out[v]){ int u = edges[i].u; auto it = find(in[u].begin(), in[u].end(), i); in[u].erase(it); pin[u] -= edges[i].cap - edges[i].flow; } } void push(int from, int to, long long f, bool forw){ qh = qt = 0; ex.assign(n, 0); ex[from] = f; q[qt++] = from; while(qh < qt){ int v = q[qh++]; if(v == to) break; long long must = ex[v]; auto it = forw ? out[v].begin() : in[v].begin(); while(true){ int u = forw ? edges[*it].u : edges[*it].v; long long pushed = min(must, edges[*it].cap - edges[*it].flow); if(pushed == 0)break; if(forw){ pout[v] -= pushed; pin[u] -= pushed; } else{ pin[v] -= pushed; pout[u] -= pushed; } if(ex[u] == 0) q[qt++] = u; ex[u] += pushed; edges[*it].flow += pushed; edges[(*it)^1].flow -= pushed; must -= pushed; if(edges[*it].cap - edges[*it].flow == 0){ auto jt = it; ++jt; if(forw){ in[u].erase(find(in[u].begin(), in[u].end(), *it)); out[v].erase(it); } else{ out[u].erase(find(out[u].begin(), out[u].end(), *it)); in[v].erase(it); } it = jt; } else break; if(!must)break; } } } long long flow(){ long long ans = 0; while(true){ pin.assign(n, 0); pout.assign(n, 0); level.assign(n, -1); alive.assign(n, true); level[s] = 0; qh = 0; qt = 1; q[0] = s; if(!bfs()) break; for(int i = 0; i < n; i++){ out[i].clear(); in[i].clear(); } for(int i = 0; i < m; i++){ if(edges[i].cap - edges[i].flow == 0) continue; int v = edges[i].v, u = edges[i].u; if(level[v] + 1 == level[u] && (level[u] < level[t] || u == t)){ in[u].push_back(i); out[v].push_back(i); pin[u] += edges[i].cap - edges[i].flow; pout[v] += edges[i].cap - edges[i].flow; } } pin[s] = pout[t] = flow_inf; while(true){ int v = -1; for(int i = 0; i < n; i++){ if(!alive[i])continue; if(v == -1 || pot(i) < pot(v)) v = i; } if(v == -1) break; if(pot(v) == 0){ alive[v] = false; remove_node(v); continue; } long long f = pot(v); ans += f; push(v, s, f, false); push(v, t, f, true); alive[v] = false; remove_node(v); } } return ans; } }MPM; int h,w; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> h >> w; MPM.init(500,0,201); for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) { char c; cin >> c; if (c == 'S') { MPM.add_edge(0,i,1e9); MPM.add_edge(0,j+100,1e9); } else if (c == 'T') { MPM.add_edge(i,201,1e9); MPM.add_edge(j+100,201,1e9); } else if (c == 'o') MPM.add_edge(i,j+100,1); } long long res = MPM.flow(); if (res >= 1e9) cout << -1; else cout << res; }
a.cc:38:5: error: ISO C++ forbids declaration of 'TEmplate_MPM' with no type [-fpermissive] 38 | TEmplate_MPM(){} | ^~~~~~~~~~~~ a.cc: In member function 'int Template_MPM::TEmplate_MPM()': a.cc:38:20: warning: no return statement in function returning non-void [-Wreturn-type] 38 | TEmplate_MPM(){} | ^
s051669435
p03718
C++
#include <bits/stdc++.h> using namespace std; struct Template_MPM{ struct FlowEdge{ int v, u; long long cap, flow; FlowEdge(){} FlowEdge(int _v, int _u, long long _cap, long long _flow) : v(_v), u(_u), cap(_cap), flow(_flow){} FlowEdge(int _v, int _u, long long _cap) : v(_v), u(_u), cap(_cap), flow(0ll){} }; const long long flow_inf = 1e18; vector<FlowEdge> edges; vector<char> alive; vector<long long> pin, pout; vector<list<int> > in, out; vector<vector<int> > adj; vector<long long> ex; int n, m = 0; int s, t; vector<int> level; vector<int> q; int qh, qt; void resize(int _n){ n = _n; ex.resize(n); q.resize(n); pin.resize(n); pout.resize(n); adj.resize(n); level.resize(n); in.resize(n); out.resize(n); } MPM(){} void init(int _n, int _s, int _t){resize(_n); s = _s; t = _t;} void add_edge(int v, int u, long long cap){ edges.push_back(FlowEdge(v, u, cap)); edges.push_back(FlowEdge(u, v, cap)); adj[v].push_back(m); adj[u].push_back(m + 1); m += 2; } bool bfs(){ while(qh < qt){ int v = q[qh++]; for(int id : adj[v]){ if(edges[id].cap - edges[id].flow < 1)continue; if(level[edges[id].u] != -1)continue; level[edges[id].u] = level[v] + 1; q[qt++] = edges[id].u; } } return level[t] != -1; } long long pot(int v){ return min(pin[v], pout[v]); } void remove_node(int v){ for(int i : in[v]){ int u = edges[i].v; auto it = find(out[u].begin(), out[u].end(), i); out[u].erase(it); pout[u] -= edges[i].cap - edges[i].flow; } for(int i : out[v]){ int u = edges[i].u; auto it = find(in[u].begin(), in[u].end(), i); in[u].erase(it); pin[u] -= edges[i].cap - edges[i].flow; } } void push(int from, int to, long long f, bool forw){ qh = qt = 0; ex.assign(n, 0); ex[from] = f; q[qt++] = from; while(qh < qt){ int v = q[qh++]; if(v == to) break; long long must = ex[v]; auto it = forw ? out[v].begin() : in[v].begin(); while(true){ int u = forw ? edges[*it].u : edges[*it].v; long long pushed = min(must, edges[*it].cap - edges[*it].flow); if(pushed == 0)break; if(forw){ pout[v] -= pushed; pin[u] -= pushed; } else{ pin[v] -= pushed; pout[u] -= pushed; } if(ex[u] == 0) q[qt++] = u; ex[u] += pushed; edges[*it].flow += pushed; edges[(*it)^1].flow -= pushed; must -= pushed; if(edges[*it].cap - edges[*it].flow == 0){ auto jt = it; ++jt; if(forw){ in[u].erase(find(in[u].begin(), in[u].end(), *it)); out[v].erase(it); } else{ out[u].erase(find(out[u].begin(), out[u].end(), *it)); in[v].erase(it); } it = jt; } else break; if(!must)break; } } } long long flow(){ long long ans = 0; while(true){ pin.assign(n, 0); pout.assign(n, 0); level.assign(n, -1); alive.assign(n, true); level[s] = 0; qh = 0; qt = 1; q[0] = s; if(!bfs()) break; for(int i = 0; i < n; i++){ out[i].clear(); in[i].clear(); } for(int i = 0; i < m; i++){ if(edges[i].cap - edges[i].flow == 0) continue; int v = edges[i].v, u = edges[i].u; if(level[v] + 1 == level[u] && (level[u] < level[t] || u == t)){ in[u].push_back(i); out[v].push_back(i); pin[u] += edges[i].cap - edges[i].flow; pout[v] += edges[i].cap - edges[i].flow; } } pin[s] = pout[t] = flow_inf; while(true){ int v = -1; for(int i = 0; i < n; i++){ if(!alive[i])continue; if(v == -1 || pot(i) < pot(v)) v = i; } if(v == -1) break; if(pot(v) == 0){ alive[v] = false; remove_node(v); continue; } long long f = pot(v); ans += f; push(v, s, f, false); push(v, t, f, true); alive[v] = false; remove_node(v); } } return ans; } }MPM; int h,w; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> h >> w; MPM.init(500,0,201); for (int i=1;i<=h;i++) for (int j=1;j<=w;j++) { char c; cin >> c; if (c == 'S') { MPM.add_edge(0,i,1e9); MPM.add_edge(0,j+100,1e9); } else if (c == 'T') { MPM.add_edge(i,201,1e9); MPM.add_edge(j+100,201,1e9); } else if (c == 'o') MPM.add_edge(i,j+100,1); } long long res = MPM.flow(); if (res >= 1e9) cout << -1; else cout << res; }
a.cc:38:5: error: ISO C++ forbids declaration of 'MPM' with no type [-fpermissive] 38 | MPM(){} | ^~~ a.cc: In member function 'int Template_MPM::MPM()': a.cc:38:11: warning: no return statement in function returning non-void [-Wreturn-type] 38 | MPM(){} | ^
s521294852
p03718
C++
include<bits/stdc++.h> #define LL long long #define MEM(x,y) memset(x,y,sizeof(x)) #define MOD(x) ((x)%mod) #define mod 1000000007 #define pb push_back #define STREAM_FAST ios::sync_with_stdio(false) using namespace std; const int maxn = 2e5+7; struct node {int v,flow,nxt;}e[maxn]; int tot=1,head[maxn],dep[maxn]; // tot starting from 1 void add(int u,int v,int w) { ++tot; e[tot].v=v;e[tot].flow=w;e[tot].nxt=head[u]; head[u]=tot; } bool bfs(int S,int T) { MEM(dep,0); dep[S]=1; queue<int>q; q.push(S); while (!q.empty()) { int u=q.front();q.pop(); for (int i=head[u];i;i=e[i].nxt) { int v=e[i].v; if (e[i].flow && !dep[v]) { dep[v]=dep[u]+1; q.push(e[i].v); } } } return dep[T]; } int aim; int dfs(int now,int flow) { if (now==aim) return flow; int f=0; for (int i=head[now];i;i=e[i].nxt) { int v=e[i].v; if (e[i].flow && dep[v]==dep[now]+1) { int x=dfs(v,min(flow,e[i].flow)); e[i].flow-=x;e[i^1].flow+=x;flow-=x;f+=x; } } if (!f) dep[now]=-2; return f; } int maxflow(int S,int T) { aim=T;int res=0; while (bfs(S,T)) res+=dfs(S,1<<30); return res; } int main() { int n,m;scanf("%d%d",&n,&m); int S=1000,T=1001; for (int i=1;i<=n;i++) { for (int j=1;j<=m;j++) { char c;scanf(" %c",&c); if (c=='o') { add(i,j+n,1);add(j+n,i,1); } else if (c=='S') { add(S,i,1e8);add(i,S,0); add(S,j+n,1e8);add(j+n,S,0); } else if (c=='T') { add(i,T,1e8);add(T,i,0); add(j+n,T,1e8);add(T,j+n,0); } } } int ans=maxflow(S,T); printf("%d\n",ans>=1e8?-1:ans); return 0; }
a.cc:1:1: error: 'include' does not name a type 1 | include<bits/stdc++.h> | ^~~~~~~ a.cc: In function 'bool bfs(int, int)': a.cc:3:18: error: 'memset' was not declared in this scope 3 | #define MEM(x,y) memset(x,y,sizeof(x)) | ^~~~~~ a.cc:23:5: note: in expansion of macro 'MEM' 23 | MEM(dep,0); | ^~~ a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' +++ |+#include <cstring> 1 | include<bits/stdc++.h> a.cc:25:5: error: 'queue' was not declared in this scope 25 | queue<int>q; | ^~~~~ a.cc:25:11: error: expected primary-expression before 'int' 25 | queue<int>q; | ^~~ a.cc:26:5: error: 'q' was not declared in this scope 26 | q.push(S); | ^ a.cc: In function 'int dfs(int, int)': a.cc:53:25: error: 'min' was not declared in this scope 53 | int x=dfs(v,min(flow,e[i].flow)); | ^~~ a.cc: In function 'int main()': a.cc:70:13: error: 'scanf' was not declared in this scope 70 | int n,m;scanf("%d%d",&n,&m); | ^~~~~ a.cc:96:5: error: 'printf' was not declared in this scope 96 | printf("%d\n",ans>=1e8?-1:ans); | ^~~~~~ a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>' +++ |+#include <cstdio> 1 | include<bits/stdc++.h>
s135566820
p03718
C++
//Zory-2020 #include<bits/stdc++.h> using namespace std; typedef long long ll; // typedef __int128 ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll<<(x)) #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++) #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--) #define mem(x,val) memset(x,val,sizeof x) bool DD=1; #define Debug if(DD) printf("line %d\n",__LINE__) #define deb(x) if(DD) cerr<<#x<<'='<<x<<endl #define debug if(DD) printf namespace mine { ll qread() { ll ans=0,f=1;char c=getchar(); while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();} while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar(); return ans*f; } void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);} void write1(ll num){write(num);putchar(' ');} void write2(ll num){write(num);putchar('\n');} template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;} template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;} ll gcd(ll x,ll y){return y?gcd(y,x%y):x;} bool IN(ll x,ll l,ll r){return l<=x and x<=r;} const int INF=0x3f3f3f3f; const int MOD=998244353; int mm(const int x){return x>=MOD?x-MOD:x;} template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);} ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;} ll invm(ll x){return qpower(x,MOD-2);} const int N=2e2+10; int hou[N]; struct Edge{int y,c,g;}e[N*N]; int ln;int oth(int x){return x&1?x+1:x-1;} void ins(int x,int y,int c) { e[++ln]=(Edge){y,c,hou[x]};hou[x]=ln; e[++ln]=(Edge){x,0,hou[y]};hou[y]=ln; } int st,ed; int h[N];queue<int> q; bool bfs() { memset(h,0,sizeof h); h[st]=1;q.push(st); while(q.size()) { int x=q.front();q.pop(); for(int k=hou[x];k>0;k=e[k].g) { int y=e[k].y; if(h[y]==0 and e[k].c>0) h[y]=h[x]+1,q.push(y); } } return h[ed]>0; } int dfs(int x,int ff) { if(x==ed) return ff; int flow=0; for(int k=hou[x];k>0;k=e[k].g) { int y=e[k].y; if(h[y]==h[x]+1 and e[k].c>0) { int out=dfs(y,min(e[k].c,ff-flow)); e[k].c-=out;e[oth(k)].c+=out;flow+=out; } if(e[k].c==0) cur[x]=e[k].g; if(flow==ff) break; } if(ff==0) h[x]=0; return flow; } char mp[N][N]; void main() { int n=qread(),m=qread();fo(i,1,n) scanf("%s",mp[i]+1); st=0,ed=n+m+1; pii S,T; fo(i,1,n) fo(j,1,m) if(mp[i][j]=='S') S={i,j},ins(st,i,INF),ins(st,n+j,INF); else if(mp[i][j]=='T') T={i,j},ins(i,ed,INF),ins(n+j,ed,INF); else if(mp[i][j]=='o') ins(i,n+j,1),ins(n+j,i,1); if(S.FR==T.FR or S.SE==T.SE) {puts("-1");return;} int ans=0;while(bfs()) ans+=dfs(st,INF);write(ans); } };//(ans+MOD)%MOD signed main() { //freopen("a.in","r",stdin); srand(time(0)); mine::main(); }
a.cc: In function 'int mine::dfs(int, int)': a.cc:85:27: error: 'cur' was not declared in this scope 85 | if(e[k].c==0) cur[x]=e[k].g; | ^~~
s254431547
p03718
C++
#include <bits/stdc++.h> #define REP(i, n) for(int i=0;i<(n);++i) #define RREP(i, n) for(int i=1;i<=(n);++i) #define ALL(v) (v).begin(), (v).end() #define RALL(v) (v).rbegin(), (v).rend() #define DUMP(x) cout<<#x<<"="<<(x)<<endl; #define pb push_back #define eb emplace_back using namespace std; typedef long long lint; typedef pair<int, int> pii; typedef pair<lint, lint> pll; const int INF = (int)1e9; struct edge{int to, cap, rev;}; int used[105]; vector<edge> G[105]; void add_edge(int from, int to, int cap){ G[from].pb({to, cap, (int)G[to].size()}); G[to].pb({from, cap, (int)G[from].size()-1}); } int dfs(int v, int t, int f){ if(v==t) return f; used[v] = 1; for(auto &e : G[v]){ if(!used[e.to] and e.cap>0){ int d = dfs(e.to, t, min(f, e.cap)); if(d>0){ e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(int s, int t){ int flow = 0; while(true){ memset(used, 0, sizeof(used)); int f = dfs(s, t, INF); if(f==0) return flow; flow += f; } } class FLotusLeaves { public: void solve(std::istream& in, std::ostream& out) { ios_base::sync_with_stdio(false); int H, W; in>>H>>W; RREP(i, H){ RREP(j, W){ char c; in>>c; if(c=='S') add_edge(0, i, INF), add_edge(0, H+j, INF); else if(c=='T') add_edge(i, H+W+1, INF), add_edge(H+j, H+W+1, INF); else if(c=='o') add_edge(i, H+j, 1); } } int ans = max_flow(0, H+W+1); if(ans>=INF) out<<"-1\n"; else out<<ans<<'\n'; } };
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s904620215
p03718
C++
//const int F = 10001; //void _(){ // int n,m; // cin >> n >> m; // vs grid(n); // cin >> grid; // MaxFlow mf; // rep(i,0,n-1) // rep(j,0,m-1){ // if(grid[i][j] == '.') continue; // mf.add_edge(i*m+j,i*m+j+n*m,1); // rep(k,0,n-1){ // if(grid[i][j] == '.') continue; // mf.add_edge(i*m+j+n*m,k*m+j,F); // } // rep(k,0,m-1){ // if(grid[i][j] == '.') continue; // mf.add_edge(i*m+j+n*m,i*m+k,F); // } // if(grid[i][j] == 'S') // mf.add_edge(mf.source,i*m+j+n*m,F); // if(grid[i][j] == 'T') // mf.add_edge(i*m+j,mf.sink,F); // } // int flow = mf.max_flow(); // if(flow >= F) // print(-1); // else // print(flow); //} // #include <numeric> #include <iomanip> #include <algorithm> #include <memory> #include <cassert> #include <vector> #include <utility> #include <iostream> #include <string> #define pb push_back #define REP_INT(i,l,r) for(int i = l; i <= r; ++i) #define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME #define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__) #define all(v) (v).begin(), (v).end() #define sz(v) ll(v.size()) #define T1 template<typename T> static using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<string> vs; T1 ostream& operator<<(ostream& stream, const vector<T>& t); T1 vector<T> unique(vector<T>& arr){ sort(all(arr)); arr.erase(unique(all(arr)), arr.end()); return arr; } T1 istream& read(T, T, istream& = cin); T1 istream& operator>>(istream& stream, vector<T>& t){ return read(all(t), stream); } T1 istream& read(T b, T e, istream& stream){ for(T it = b; it != e; ++it) stream >> *it; return stream; } T1 void print(T x, string end = "\n"){ cout << x << end; } template <typename COST_TYPE = ll> struct MaxFlow{ const ll FLOW_INF = 1e18; bool needs_prep; struct FlowTracker{ ll *cap, *rcap; shared_ptr<ll> flow; bool dir; FlowTracker(){ dir = 0; cap = rcap = NULL; } FlowTracker(ll *_cap, ll *_rcap, shared_ptr<ll> _flow, int _dir) :cap(_cap), rcap(_rcap), flow(_flow), dir(_dir){ } ll rem()const{ if(dir == 0){ return *cap - *flow; }else{ return *rcap + *flow; } } void add_flow(ll f){ if(dir == 0) *flow += f; else *flow -= f; assert(*flow <= *cap); assert(-*flow <= *rcap); } operator ll()const{ return rem(); } void clear(){ *flow = 0; } void operator-=(ll x){ add_flow(x); } void operator+=(ll x){ add_flow(-x); } }; struct Edge{ int u, v; ll c, rc; COST_TYPE cost; FlowTracker flow; Edge(){} Edge(int _u, int _v, ll _c, COST_TYPE _cost = 0) :u(_u), v(_v), c(_c), cost(_cost){ rc = 0; } void change_cap(ll _c, ll _rc = 0){ c = _c; rc = _rc; } }; int source, sink, rt_source, rt_sink; MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){ needs_prep = true; } vector<vector<int>> adj; vector<vector<COST_TYPE>> cost; vector<vector<FlowTracker>> cap; vector<Edge> edges; int add_edge(int u, int v, ll c, COST_TYPE cost = 0){ needs_prep = true; edges.push_back(Edge(u, v, c, cost)); return sz(edges) - 1; } vector<int> now, lvl; vector<COST_TYPE> pot; vi indices; void prep(){ if(!needs_prep){ for(auto &_ : edges) _.flow.clear(); return; } needs_prep = false; indices = vi{source,sink}; for(auto& edge : edges){ indices.push_back(edge.u); indices.push_back(edge.v); } sort(indices.begin(), indices.end()); indices.erase(unique(indices.begin(), indices.end()), indices.end()); rt_source = lower_bound(indices.begin(), indices.end(), source) - indices.begin(); rt_sink = lower_bound(indices.begin(), indices.end(), sink) - indices.begin(); adj.clear(); cost.clear(); cap.clear(); now.clear(); lvl.clear(); pot.clear(); int max_id = sz(indices) - 1; adj.resize(max_id + 1); cost.resize(max_id + 1); cap.resize(max_id + 1); now.resize(max_id + 1); lvl.resize(max_id + 1); pot.resize(max_id + 1); vi ordering(sz(edges)); iota(all(ordering),0); random_shuffle(all(ordering)); for(int id : ordering){ auto &edge = edges[id]; int u = lower_bound(indices.begin(), indices.end(), edge.u) - indices.begin(); int v = lower_bound(indices.begin(), indices.end(), edge.v) - indices.begin(); auto flow = make_shared<ll>(0); adj[u].push_back(v); cost[u].push_back(edge.cost); cap[u].push_back(FlowTracker(&edge.c, &edge.rc, flow, 0)); if(u != v){ adj[v].push_back(u); cost[v].push_back(-edge.cost); cap[v].push_back(FlowTracker(&edge.c, &edge.rc, flow, 1)); } assert(cap[u].back() == edge.c); edge.flow = cap[v].back(); } } int get_name(int x){ auto it = lower_bound(all(indices),x); if(it == indices.end() || *it != x){ indices.pb(x); unique(indices); needs_prep = true; it = lower_bound(all(indices),x); } assert(*it == x); return it-indices.begin(); } void set_source(int _source){ if(source == _source) return; source = _source; rt_source = get_name(source); } void set_sink(int _sink){ if(sink == _sink) return; sink = _sink; rt_sink = get_name(sink); } bool dinic_bfs(){ fill(now.begin(), now.end(), 0); fill(lvl.begin(), lvl.end(), 0); lvl[rt_source] = 1; vector<int> bfs(1, rt_source); for(int i = 0; i < sz(bfs); ++i){ int u = bfs[i]; for(int j = 0; j < sz(adj[u]); ++j){ int v = adj[u][j]; if(cap[u][j] > 0 && lvl[v] == 0){ lvl[v] = lvl[u] + 1; bfs.push_back(v); } } } return lvl[rt_sink] > 0; } ll dinic_dfs(int u, ll flow){ if(u == rt_sink) return flow; while(now[u] < sz(adj[u])){ int v = adj[u][now[u]]; if(lvl[v] == lvl[u] + 1 && cap[u][now[u]] != 0){ ll res = dinic_dfs(v, min(flow, (ll)cap[u][now[u]])); if(res > 0){ cap[u][now[u]] -= res; return res; } } ++now[u]; } return 0; } ll max_flow(int _source, int _sink){ set_source(_source); set_sink(_sink); prep(); ll ans = 0; while(dinic_bfs()){ ll cur = 0; do{ cur = dinic_dfs(rt_source, FLOW_INF); ans += cur; }while(cur > 0); } return ans; } ll max_flow(){ return max_flow(source, sink); } }; const int F = 10001; void _(){ int n,m; cin >> n >> m; vs grid(n); cin >> grid; MaxFlow mf; rep(i,0,n-1) rep(j,0,m-1){ if(grid[i][j] == '.') continue; mf.add_edge(i*m+j,i*m+j+n*m,1); rep(k,0,n-1){ if(grid[i][j] == '.') continue; mf.add_edge(i*m+j+n*m,k*m+j,F); } rep(k,0,m-1){ if(grid[i][j] == '.') continue; mf.add_edge(i*m+j+n*m,i*m+k,F); } if(grid[i][j] == 'S') mf.add_edge(mf.source,i*m+j+n*m,F); if(grid[i][j] == 'T') mf.add_edge(i*m+j,mf.sink,F); } int flow = mf.max_flow(); if(flow >= F) print(-1); else print(flow); } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); _(); }
a.cc:129:27: error: 'numeric_limits' was not declared in this scope 129 | MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){ | ^~~~~~~~~~~~~~ a.cc:129:42: error: expected primary-expression before 'int' 129 | MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){ | ^~~ a.cc:129:67: error: 'numeric_limits' was not declared in this scope 129 | MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){ | ^~~~~~~~~~~~~~ a.cc:129:82: error: expected primary-expression before 'int' 129 | MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){ | ^~~ a.cc: In member function 'void MaxFlow<COST_TYPE>::prep()': a.cc:175:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations] 175 | random_shuffle(all(ordering)); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ In file included from /usr/include/c++/14/algorithm:61, from a.cc:34: /usr/include/c++/14/bits/stl_algo.h:4492:5: note: declared here 4492 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) | ^~~~~~~~~~~~~~ a.cc: In instantiation of 'void MaxFlow<COST_TYPE>::prep() [with COST_TYPE = long long int]': a.cc:250:9: required from 'll MaxFlow<COST_TYPE>::max_flow(int, int) [with COST_TYPE = long long int; ll = long long int]' 250 | prep(); | ^~~~ a.cc:262:24: required from 'll MaxFlow<COST_TYPE>::max_flow() [with COST_TYPE = long long int; ll = long long int]' 262 | return max_flow(source, sink); | ~~~~~~~~^~~~~~~~~~~~~~ a.cc:289:27: required from here 289 | int flow = mf.max_flow(); | ~~~~~~~~~~~^~ a.cc:175:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations] 175 | random_shuffle(all(ordering)); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:4492:5: note: declared here 4492 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) | ^~~~~~~~~~~~~~ a.cc:175:23: warning: 'void std::random_shuffle(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<int*, vector<int> >]' is deprecated: use 'std::shuffle' instead [-Wdeprecated-declarations] 175 | random_shuffle(all(ordering)); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:4492:5: note: declared here 4492 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) | ^~~~~~~~~~~~~~
s204483102
p03718
C++
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <fstream> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <bitset> #include <array> #include <vector> #include <queue> #include <set> #include <cmath> // 変数名にy1が使えなくなるかも…。 #include <map> #include <unordered_map> #include <unordered_set> #include <limits> #include <string> typedef __int128_t int128_t; std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。 long long tmp; input >> tmp; value = tmp; return input; } std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。 output << (long long)value; return output; } class Directed_Graph { public: struct Edge { int to; int128_t cost; }; typedef std::vector<std::vector<Edge>> adj_list; adj_list G; int node_num; Directed_Graph() {} Directed_Graph(const int node_num_in) { node_num = node_num_in; G.resize(node_num); } void add_edge(const int from, const int to, const long long cost) { Edge edge; edge.to = to; edge.cost = cost; G[from].push_back(edge); } void add_edge_both(const int node1, const int node2, const long long cost) { add_edge(node1, node2, cost); add_edge(node2, node1, cost); } // 点sからの最短距離の配列を返す。 // 戻りの値としてint128_tを用い、初期値としてint64_tの最大値を用いるのは、dist[v] + edge.costの計算でのオーバーフローを防ぐため。 // 正しい最短距離がint64_tの最大値を超えるような事態は想定していないので、最終的にdist[v] == std::numeric_limits<int64_t>::max()だった場合、vには到達できないことを意味する。 std::vector<int128_t> Dijkstra(int s) { std::vector<int128_t> dist; dist.resize(node_num, std::numeric_limits<int64_t>::max()); typedef std::pair<int128_t, int> Pair; std::priority_queue <Pair, std::vector<Pair>, std::greater<Pair>> que; dist[s] = 0; que.push(Pair(0, s)); while (!que.empty()) { Pair pair = que.top(); que.pop(); int v = pair.second; if (dist[v] < pair.first) { continue; } for (Edge edge : G[v]) { if (dist[v] + edge.cost < dist[edge.to]) { dist[edge.to] = dist[v] + edge.cost; que.push(Pair(dist[edge.to], edge.to)); } } } return dist; } std::vector<std::vector<int128_t>> Warshall_Floyd(const long long dist_inf) { std::vector<std::vector<int128_t>> dist; dist.resize(node_num); for (int i = 0; i < dist.size(); i++) { dist[i].resize(node_num); for (int j = 0; j < dist[i].size(); j++) { dist[i][j] = dist_inf; } dist[i][i] = 0; for (auto e : G[i]) { dist[i][e.to] = std::min(dist[i][e.to], e.cost); } } for (int k = 0; k < node_num; k++) { for (int i = 0; i < node_num; i++) { for (int j = 0; j < node_num; j++) { dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]); } } } return dist; } bool bipartite_search(const int node, const int c, std::vector<int>& ret) { assert(c == 1 || c == -1); assert(node < ret.size()); if (ret[node] == -c) { return false; } if (ret[node] == c) { return true; } assert(ret[node] == 0); ret[node] = c; for (Edge e : G[node]) { if (!bipartite_search(e.to, -c, ret)) { return false; } } return true; } std::pair<bool, std::vector<int>> is_bipartite(const int begin, const int end) { std::vector<int> ret; ret.resize(end+1, 0); for (int i = begin; i <= end; i++) { if (ret[i] == 0 && !bipartite_search(i, 1, ret)) { return std::pair<bool, std::vector<int>>({false, ret}); } } return std::pair<bool, std::vector<int>>({true, ret}); } std::pair<adj_list, std::vector<std::vector<int>>> auxilarity_network() const { adj_list Net; std::vector<std::vector<int>> Rev; Net.resize(node_num); Rev.resize(node_num); for (int i = 0; i < node_num; i++) { for (Edge e : G[i]) { Net[i].push_back(e); Rev[i].push_back(-1); } } for (int i = 0; i < node_num; i++) { for (int j = 0; j < G[i].size(); j++) { Edge r; r.to = i; r.cost = 0; Rev[i][j] = Net[G[i][j].to].size(); Net[G[i][j].to].push_back(r); Rev[G[i][j].to].push_back(j); } } return std::pair<adj_list, std::vector<std::vector<int>>>({Net, Rev}); } int64_t dfs_increase_path(const int v, const int t, const int64_t f, std::vector<bool>& used, adj_list& Net, const std::vector<std::vector<int>>& Rev) const { if (v == t) { return f; } used[v] = true; for (int i = 0; i < Net[v].size(); i++) { Edge &e = Net[v][i]; if (!used[e.to] && 0 < e.cost) { //std::cout << v << " " << e.to << std::endl; int d = dfs_increase_path(e.to, t, std::min(f, e.cost), used, Net, Rev); //std::cout << v << " " << e.to << " " << d << " " << std::endl; if (0 < d) { e.cost -= d; Net[e.to][Rev[v][i]].cost += d; return d; } } } return 0; } std::pair<int64_t, adj_list> max_flow(const int s, const int t) const { auto aux = auxilarity_network(); int64_t flow = 0; //std::cout << "flow:" << flow << " " << aux.first[2][0].to << " " << aux.first[2][0].cost << std::endl; //std::cout << "flow:" << flow << " " << aux.first[6][0].to << " " << aux.first[6][0].cost << std::endl; while (true) { std::vector<bool> used; used.resize(node_num, false); int64_t f = dfs_increase_path(s, t, std::numeric_limits<int64_t>::max(), used, aux.first, aux.second); if (f == 0) { break; } flow += f; //std::cout << "flow:" << flow << " " << aux.first[2][0].to << " " << aux.first[2][0].cost << std::endl; //std::cout << "flow:" << flow << " " << aux.first[6][0].to << " " << aux.first[6][0].cost << std::endl; //if (2 < flow) { // break; //} } adj_list ret; ret.resize(node_num); for (int i = 0; i < node_num; i++) { for (int j = 0; j < G[i].size(); j++) { ret[i].push_back(G[i][j]); ret[i][j].cost -= aux.first[i][j].cost; } } return std::pair<int64_t, adj_list>({ flow, ret }); } }; const int MAX_N = 110; int H, W; char a[MAX_N][MAX_N]; Directed_Graph dg = Directed_Graph(MAX_N * MAX_N * 2); int main(int argc, char **argv) { std::cin >> H >> W; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { std::cin >> a[i][j]; } } //std::cout << "check1" << std::endl; int si, sj, ti, tj; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (a[i][j] == 'o') { dg.add_edge(i*W + j, i*W + j + H*W, 1); } else if (a[i][j] == 'S') { si = i; sj = j; } else if (a[i][j] == 'T') { ti = i; tj = j; } } } if (si == ti || sj == tj) { std::cout << -1 << std::endl; return 0; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < W; k++) { if (j != k && (a[i][j] == 'o' || a[i][j] == 'S') && (a[i][k] == 'o' || a[i][k] == 'T')) { dg.add_edge(i*W + j + H*W, i*W + k, 1); } } } } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { for (int k = 0; k < H; k++) { if (j != k && (a[j][i] == 'o' || a[j][i] == 'S') && (a[k][i] == 'o' || a[k][i] == 'T')) { dg.add_edge(j*W + i + H*W, k*W + i, 1); } } } } //std::cout << si << " " << sj << " " << ti << " " << tj << std::endl; //std::cout << "check2" << std::endl; auto ret = dg.max_flow(si*W + sj + H*W, ti*W + tj); std::cout << ret.first << std::endl; return 0; }
a.cc: In member function 'int64_t Directed_Graph::dfs_increase_path(int, int, int64_t, std::vector<bool>&, adj_list&, const std::vector<std::vector<int> >&) const': a.cc:152:60: error: no matching function for call to 'min(const int64_t&, int128_t&)' 152 | int d = dfs_increase_path(e.to, t, std::min(f, e.cost), used, Net, Rev); | ~~~~~~~~^~~~~~~~~~~ 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/istream:40, from /usr/include/c++/14/fstream:40, from a.cc:4: /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:152:60: note: deduced conflicting types for parameter 'const _Tp' ('long int' and 'int128_t' {aka '__int128'}) 152 | int d = dfs_increase_path(e.to, t, std::min(f, e.cost), used, Net, Rev); | ~~~~~~~~^~~~~~~~~~~ /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, from a.cc:8: /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:152:60: note: mismatched types 'std::initializer_list<_Tp>' and 'long int' 152 | int d = dfs_increase_path(e.to, t, std::min(f, e.cost), used, Net, Rev); | ~~~~~~~~^~~~~~~~~~~
s208524712
p03718
C++
#include <stdio.h> #include <stdlib.h> #include <assert.h> #include <fstream> #include <iostream> #include <sstream> #include <iomanip> #include <algorithm> #include <bitset> #include <array> #include <vector> #include <queue> #include <set> #include <cmath> // 変数名にy1が使えなくなるかも…。 #include <map> #include <unordered_map> #include <unordered_set> #include <limits> #include <string> typedef __int128_t int128_t; std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。 long long tmp; input >> tmp; value = tmp; return input; } std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。 output << (long long)value; return output; } class Directed_Graph { public: struct Edge { int to; int64_t cost; }; typedef std::vector<std::vector<Edge>> adj_list; adj_list G; int node_num; Directed_Graph() {} Directed_Graph(const int node_num_in) { node_num = node_num_in; G.resize(node_num); } void add_edge(const int from, const int to, const long long cost) { Edge edge; edge.to = to; edge.cost = cost; G[from].push_back(edge); } void add_edge_both(const int node1, const int node2, const long long cost) { add_edge(node1, node2, cost); add_edge(node2, node1, cost); } // 点sからの最短距離の配列を返す。 // 戻りの値としてint128_tを用い、初期値としてint64_tの最大値を用いるのは、dist[v] + edge.costの計算でのオーバーフローを防ぐため。 // 正しい最短距離がint64_tの最大値を超えるような事態は想定していないので、最終的にdist[v] == std::numeric_limits<int64_t>::max()だった場合、vには到達できないことを意味する。 std::vector<int128_t> Dijkstra(int s) { std::vector<int128_t> dist; dist.resize(node_num, std::numeric_limits<int64_t>::max()); typedef std::pair<int128_t, int> Pair; std::priority_queue <Pair, std::vector<Pair>, std::greater<Pair>> que; dist[s] = 0; que.push(Pair(0, s)); while (!que.empty()) { Pair pair = que.top(); que.pop(); int v = pair.second; if (dist[v] < pair.first) { continue; } for (Edge edge : G[v]) { if (dist[v] + edge.cost < dist[edge.to]) { dist[edge.to] = dist[v] + edge.cost; que.push(Pair(dist[edge.to], edge.to)); } } } return dist; } std::vector<std::vector<long long>> Warshall_Floyd(const long long dist_inf) { std::vector<std::vector<long long>> dist; dist.resize(node_num); for (int i = 0; i < dist.size(); i++) { dist[i].resize(node_num); for (int j = 0; j < dist[i].size(); j++) { dist[i][j] = dist_inf; } dist[i][i] = 0; for (auto e : G[i]) { dist[i][e.to] = std::min(dist[i][e.to], e.cost); } } for (int k = 0; k < node_num; k++) { for (int i = 0; i < node_num; i++) { for (int j = 0; j < node_num; j++) { dist[i][j] = std::min(dist[i][j], dist[i][k] + dist[k][j]); } } } return dist; } bool bipartite_search(const int node, const int c, std::vector<int>& ret) { assert(c == 1 || c == -1); assert(node < ret.size()); if (ret[node] == -c) { return false; } if (ret[node] == c) { return true; } assert(ret[node] == 0); ret[node] = c; for (Edge e : G[node]) { if (!bipartite_search(e.to, -c, ret)) { return false; } } return true; } std::pair<bool, std::vector<int>> is_bipartite(const int begin, const int end) { std::vector<int> ret; ret.resize(end+1, 0); for (int i = begin; i <= end; i++) { if (ret[i] == 0 && !bipartite_search(i, 1, ret)) { return std::pair<bool, std::vector<int>>({false, ret}); } } return std::pair<bool, std::vector<int>>({true, ret}); } std::pair<adj_list, std::vector<std::vector<int>>> auxilarity_network() const { adj_list Net; std::vector<std::vector<int>> Rev; Net.resize(node_num); Rev.resize(node_num); for (int i = 0; i < node_num; i++) { for (Edge e : G[i]) { Net[i].push_back(e); Rev[i].push_back(-1); } } for (int i = 0; i < node_num; i++) { for (int j = 0; j < G[i].size(); j++) { Edge r; r.to = i; r.cost = 0; Rev[i][j] = Net[G[i][j].to].size(); Net[G[i][j].to].push_back(r); Rev[G[i][j].to].push_back(j); } } return std::pair<adj_list, std::vector<std::vector<int>>>({Net, Rev}); } int64_t dfs_increase_path(const int v, const int t, const int64_t f, std::vector<bool>& used, adj_list& Net, const std::vector<std::vector<int>>& Rev) const { if (v == t) { return f; } used[v] = true; for (int i = 0; i < Net[v].size(); i++) { Edge &e = Net[v][i]; if (!used[e.to] && 0 < e.cost) { //std::cout << v << " " << e.to << std::endl; int d = dfs_increase_path(e.to, t, std::min(f, e.cost), used, Net, Rev); //std::cout << v << " " << e.to << " " << d << " " << std::endl; if (0 < d) { e.cost -= d; Net[e.to][Rev[v][i]].cost += d; return d; } } } return 0; } std::pair<int64_t, adj_list> max_flow(const int s, const int t) const { auto aux = auxilarity_network(); int64_t flow = 0; //std::cout << "flow:" << flow << " " << aux.first[2][0].to << " " << aux.first[2][0].cost << std::endl; //std::cout << "flow:" << flow << " " << aux.first[6][0].to << " " << aux.first[6][0].cost << std::endl; while (true) { std::vector<bool> used; used.resize(node_num, false); int64_t f = dfs_increase_path(s, t, std::numeric_limits<int64_t>::max(), used, aux.first, aux.second); if (f == 0) { break; } flow += f; //std::cout << "flow:" << flow << " " << aux.first[2][0].to << " " << aux.first[2][0].cost << std::endl; //std::cout << "flow:" << flow << " " << aux.first[6][0].to << " " << aux.first[6][0].cost << std::endl; //if (2 < flow) { // break; //} } adj_list ret; ret.resize(node_num); for (int i = 0; i < node_num; i++) { for (int j = 0; j < G[i].size(); j++) { ret[i].push_back(G[i][j]); ret[i][j].cost -= aux.first[i][j].cost; } } return std::pair<int64_t, adj_list>({ flow, ret }); } }; const int MAX_N = 110; int H, W; char a[MAX_N][MAX_N]; Directed_Graph dg = Directed_Graph(MAX_N * MAX_N * 2); int main(int argc, char **argv) { std::cin >> H >> W; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { std::cin >> a[i][j]; } } //std::cout << "check1" << std::endl; int si, sj, ti, tj; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (a[i][j] == 'o') { dg.add_edge(i*W + j, i*W + j + H*W, 1); } else if (a[i][j] == 'S') { si = i; sj = j; } else if (a[i][j] == 'T') { ti = i; tj = j; } } } if (si == ti || sj == tj) { std::cout << -1 << std::endl; return 0; } for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { for (int k = 0; k < W; k++) { if (j != k && (a[i][j] == 'o' || a[i][j] == 'S') && (a[i][k] == 'o' || a[i][k] == 'T')) { dg.add_edge(i*W + j + H*W, i*W + k, 1); } } } } for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { for (int k = 0; k < H; k++) { if (j != k && (a[j][i] == 'o' || a[j][i] == 'S') && (a[k][i] == 'o' || a[k][i] == 'T')) { dg.add_edge(j*W + i + H*W, k*W + i, 1); } } } } //std::cout << si << " " << sj << " " << ti << " " << tj << std::endl; //std::cout << "check2" << std::endl; auto ret = dg.max_flow(si*W + sj + H*W, ti*W + tj); std::cout << ret.first << std::endl; return 0; }
a.cc: In member function 'std::vector<std::vector<long long int> > Directed_Graph::Warshall_Floyd(long long int)': a.cc:88:41: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type&, int64_t&)' 88 | dist[i][e.to] = std::min(dist[i][e.to], e.cost); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ 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/istream:40, from /usr/include/c++/14/fstream:40, from a.cc:4: /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:88:41: note: deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t' {aka 'long int'}) 88 | dist[i][e.to] = std::min(dist[i][e.to], e.cost); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~ /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, from a.cc:8: /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:88:41: note: mismatched types 'std::initializer_list<_Tp>' and 'long long int' 88 | dist[i][e.to] = std::min(dist[i][e.to], e.cost); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
s077746594
p03718
C++
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #define rep(i,l,r) for(int i=(l);i<=(r);++i) #define per(i,r,l) for(int i=(r);i>=(l);--i) #define pb push_back using namespace std; const int maxn=210,inf=1e9; int n,m,cnt=2,p[maxn],q[maxn];char s[maxn][maxn]; struct edge{int from,to,cap,flow;}; struct D{ vector<edge> e; vector<int> G[maxn]; int n,m,s,t,vis[maxn],d[maxn],cur[maxn]; inline void add(int from,int to,int cap){ e.pb((edge){from,to,cap,0});e.pb((edge){to,from,cap,0}); m=e.size();G[from].pb(m-2);G[to].pb(m-1); } bool bfs(){ memset(vis,0,sizeof(vis));memset(d,0,sizeof(d));o..o....So queue<int> q;q.push(s);vis[s]=1; while(!q.empty()){ int u=q.front();q.pop(); rep(i,0,(int)G[u].size()-1){ edge &E=e[G[u][i]]; if(!vis[E.to]&&E.cap>E.flow){ d[E.to]=d[u]+1; q.push(E.to); vis[E.to]=1; } } } return vis[t]; } int dfs(int u,int a){ if(u==t||a==0) return a; int flow=0,f; for(int &i=cur[u];i<G[u].size();++i){ edge &E=e[G[u][i]]; if(d[E.to]==d[u]+1&&(f=dfs(E.to,min(E.cap-E.flow,a)))){ o..o....So o..o....So o..o....So }o..o....So } return flow; } int max_flow(int s,int t){ this->s=s,this->t=t; int flow=0; while(bfs()){ memset(cur,0,sizeof(cur)); flow+=dfs(s,inf); } return flow; } }D; int main(){ scanf("%d%d",&n,&m);int S=1,T=2; rep(i,1,n) rep(j,1,m){ scanf(" %c",&s[i][j]); if(s[i][j]=='S'){ if(p[i]||q[j]) return puts("-1"),0; p[i]=S,q[j]=S; } if(s[i][j]=='T'){ if(p[i]||q[j]) return puts("-1"),0; p[i]=T,q[j]=T; } } rep(i,1,n) if(!p[i]) p[i]=++cnt; rep(i,1,m) if(!q[i]) q[i]=++cnt;D.n=cnt; rep(i,1,n) rep(j,1,m) if(s[i][j]=='o') D.add(p[i],q[j],1); printf("%d\n",D.max_flow(S,T)); return 0; }
a.cc: In member function 'bool D::bfs()': a.cc:28:57: error: 'o' was not declared in this scope 28 | memset(vis,0,sizeof(vis));memset(d,0,sizeof(d));o..o....So | ^ a.cc:28:59: error: expected unqualified-id before '.' token 28 | memset(vis,0,sizeof(vis));memset(d,0,sizeof(d));o..o....So | ^ a.cc:29:24: error: request for member 'push' in 'q', which is of non-class type 'int [210]' 29 | queue<int> q;q.push(s);vis[s]=1; | ^~~~ a.cc:30:18: error: request for member 'empty' in 'q', which is of non-class type 'int [210]' 30 | while(!q.empty()){ | ^~~~~ a.cc:31:21: error: request for member 'front' in 'q', which is of non-class type 'int [210]' 31 | int u=q.front();q.pop(); | ^~~~~ a.cc:31:31: error: request for member 'pop' in 'q', which is of non-class type 'int [210]' 31 | int u=q.front();q.pop(); | ^~~ a.cc:36:23: error: request for member 'push' in 'q', which is of non-class type 'int [210]' 36 | q.push(E.to); | ^~~~ a.cc: In member function 'int D::dfs(int, int)': a.cc:49:14: error: 'o' was not declared in this scope 49 | o..o....So | ^ a.cc:49:16: error: expected unqualified-id before '.' token 49 | o..o....So | ^ a.cc:52:14: error: 'o' was not declared in this scope 52 | }o..o....So | ^ a.cc:52:16: error: expected unqualified-id before '.' token 52 | }o..o....So | ^
s391721871
p03718
C++
#include <bits/stdc++.h> using namespace std; template<typename T> class fixed_point : T { public: explicit constexpr fixed_point ( T&& t ) noexcept : T(forward<T>(t)) { } template<typename... Args> constexpr decltype(auto) operator()( Args&&... args ) const { return T::operator()(*this, forward<Args>(args)...); } }; template<typename T> static inline constexpr decltype(auto) fix (T&& t) noexcept { return fixed_point<T>{forward<T>(t)}; } int main() { cin.tie(0); cin.sync_with_stdio(false); int h, w; cin >> h >> w; vector<string> str(h, string(w, '$')); int si, sj, ti, tj; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> str[i][j]; if (str[i][j] == 'S') si = i, sj = j; if (str[i][j] == 'T') ti = i, tj = j; } } if (si == ti || sj == ti) { cout << -1 << endl; return -; } int source = si, sink = ti; vector<vector<int>> grh(h + w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { char c = str[i][j]; if (c != '.') { grh[i ].push_back(h + j); grh[h + j].push_back(i ); } } } int ret = 0; while (true) { vector<bool> ckd(h + w, false); int d = fix ([&](auto dfs, int crr) -> int { if (crr == sink) return 1; if (ckd[crr]) return 0; ckd[crr] = true; for (auto const& nxt : grh[crr]) { if (dfs(nxt)) { int i = crr, j = nxt; if (i > j) swap(i, j); j -= h; if ( (i == si && j == sj) || (i == ti && j == tj) ) { grh[crr].erase(find(grh[crr].begin(), grh[crr].end(), nxt)); grh[nxt].push_back(crr); } return 1; } } return 0; })(source); if (d == 0) break; ret++; } if (si == ti || sj == tj) { cout << -1 << endl; return 0; } cout << ret << endl; return 0; }
a.cc: In function 'int main()': a.cc:40:13: error: expected primary-expression before ';' token 40 | return -; | ^
s625631382
p03718
C++
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #include<queue> #include<cstring> using namespace std; const int maxn=1e4+5; const int maxm=4e4+5; const int inf=1e9; int k,l,p,q,maxx; struct edge { int fr,to,nxt; int c,f; }graph[maxm]; int head[maxn]; int tot; int level[maxn]; int n,m; int s,t; string str; struct node { int x,y,id; }a[maxn],start,end; bool cmp(node a,node b) { return a.y<b.y; } bool dinic_bfs() { memset(level,0,sizeof(level)); queue<int> que; que.push(s); level[s] = 1; while (!que.empty()) { int u = que.front(); que.pop(); for (int i = head[u]; i != -1; i = graph[i].nxt) { int v = graph[i].to; if (!level[v] && graph[i].c > graph[i].f) { level[v] = level[u] + 1; que.push(v); } } } return level[t] != 0; } int dinic_dfs(int u, int cpflow) { if (u == t) return cpflow; int addflow = 0; for (int i = head[u]; i != -1 && addflow < cpflow; i = graph[i].nxt) { int v = graph[i].to; if (level[u] + 1 == level[v] && graph[i].c > graph[i].f) { int tmpadd = dinic_dfs(v, min(cpflow - addflow, graph[i].c - graph[i].f)); graph[i].f += tmpadd; graph[i ^ 1].f -= tmpadd; addflow += tmpadd; } } return addflow; } int dinic() { int maxflow = 0; while (dinic_bfs()) maxflow += dinic_dfs(s, inf); return maxflow; } void addEdge(int u,int v,int c, int i) { graph[tot].to = v; graph[tot].fr = u; graph[tot].nxt = head[u]; graph[tot].c = c; graph[tot].f = 0; head[u] = tot++; graph[tot].to = u; graph[tot].fr = v; graph[tot].nxt = head[v]; graph[tot].c = 0; graph[tot].f = 0; head[v] = tot++; } void init() { for(int i=1;i<maxn;i++) head[i]=-1; tot=0; } int main() { int cnt=0; init(); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { cin>>str; for(int j=0;j<m;j++) { if(str[j]!='.') { cnt++; a[cnt].x=i,a[cnt].y=j+1,a[cnt].id=cnt; if(str[j]=='S') { s=cnt; start.x=a[cnt].x,start.y=a[cnt].y,start.id=a[cnt].id; } if(str[j]=='T') { t=cnt; end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; } } } } for(int i=1;i<cnt;i++) { if(a[i].x==a[i+1].x) { addEdge(a[i].id,a[i+1].id,1,0); addEdge(a[i+1].id,a[i].id,1,0); } } sort(a+1,a+1+cnt,cmp); for(int i=1;i<cnt;i++) { if(a[i].y==a[i+1].y) { addEdge(a[i].id,a[i+1].id,1,0); addEdge(a[i+1].id,a[i].id,1,0); } } if(start.y==end.y||start.x==end.x) { cout<<-1<<endl; return 0; } cout<<dinic(); return 0; }
a.cc: In function 'int main()': a.cc:128:41: error: reference to 'end' is ambiguous 128 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ 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:1: /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ In file included from /usr/include/c++/14/bits/range_access.h:36: /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:28:16: note: 'node end' 28 | }a[maxn],start,end; | ^~~ a.cc:128:56: error: reference to 'end' is ambiguous 128 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:28:16: note: 'node end' 28 | }a[maxn],start,end; | ^~~ a.cc:128:71: error: reference to 'end' is ambiguous 128 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:28:16: note: 'node end' 28 | }a[maxn],start,end; | ^~~ a.cc:150:21: error: reference to 'end' is ambiguous 150 | if(start.y==end.y||start.x==end.x) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:28:16: note: 'node end' 28 | }a[maxn],start,end; | ^~~ a.cc:150:37: error: reference to 'end' is ambiguous 150 | if(start.y==end.y||start.x==end.x) | ^~~ /usr/include/c++/14/bits/range_access.h:116:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:115:31: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 115 | template<typename _Tp> _Tp* end(valarray<_Tp>&) noexcept; | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:28:16: note: 'node end' 28 | }a[maxn],start,end; | ^~~
s040796759
p03718
C++
#include<bits/stdc++.h> using namespace std; const int maxn=1e4+5; const int maxm=4e4+5; const int inf=1e9; int k,l,p,q,maxx; struct edge { int fr,to,nxt; int c,f; }graph[maxm]; int head[maxn]; int tot; int level[maxn]; int n,m; int s,t; string str; struct node { int x,y,id; }a[maxn],start,end; bool cmp(node a,node b) { return a.y<b.y; } bool dinic_bfs() { memset(level,0,sizeof(level)); queue<int> que; que.push(s); level[s] = 1; while (!que.empty()) { int u = que.front(); que.pop(); for (int i = head[u]; i != -1; i = graph[i].nxt) { int v = graph[i].to; if (!level[v] && graph[i].c > graph[i].f) { level[v] = level[u] + 1; que.push(v); } } } return level[t] != 0; } int dinic_dfs(int u, int cpflow) { if (u == t) return cpflow; int addflow = 0; for (int i = head[u]; i != -1 && addflow < cpflow; i = graph[i].nxt) { int v = graph[i].to; if (level[u] + 1 == level[v] && graph[i].c > graph[i].f) { int tmpadd = dinic_dfs(v, min(cpflow - addflow, graph[i].c - graph[i].f)); graph[i].f += tmpadd; graph[i ^ 1].f -= tmpadd; addflow += tmpadd; } } return addflow; } int dinic() { int maxflow = 0; while (dinic_bfs()) maxflow += dinic_dfs(s, inf); return maxflow; } void addEdge(int u,int v,int c, int i) { graph[tot].to = v; graph[tot].fr = u; graph[tot].nxt = head[u]; graph[tot].c = c; graph[tot].f = 0; head[u] = tot++; graph[tot].to = u; graph[tot].fr = v; graph[tot].nxt = head[v]; graph[tot].c = 0; graph[tot].f = 0; head[v] = tot++; } void init() { for(int i=1;i<maxn;i++) head[i]=-1; tot=0; } int main() { int cnt=0; init(); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { cin>>str; for(int j=0;j<m;j++) { if(str[j]!='.') { cnt++; a[cnt].x=i,a[cnt].y=j+1,a[cnt].id=cnt; if(str[j]=='S') { s=cnt; start.x=a[cnt].x,start.y=a[cnt].y,start.id=a[cnt].id; } if(str[j]=='T') { t=cnt; end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; } } } } for(int i=1;i<cnt;i++) { if(a[i].x==a[i+1].x) { addEdge(a[i].id,a[i+1].id,1,0); addEdge(a[i+1].id,a[i].id,1,0); } } sort(a+1,a+1+cnt,cmp); for(int i=1;i<cnt;i++) { if(a[i].y==a[i+1].y) { addEdge(a[i].id,a[i+1].id,1,0); addEdge(a[i+1].id,a[i].id,1,0); } } if(start.y==end.y||start.x==end.x) { cout<<-1<<endl; return 0; } cout<<dinic(); return 0; }
a.cc: In function 'int main()': a.cc:123:41: error: reference to 'end' is ambiguous 123 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166, from a.cc:1: /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ In file included from /usr/include/c++/14/string:53, 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/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:23:16: note: 'node end' 23 | }a[maxn],start,end; | ^~~ a.cc:123:56: error: reference to 'end' is ambiguous 123 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:23:16: note: 'node end' 23 | }a[maxn],start,end; | ^~~ a.cc:123:71: error: reference to 'end' is ambiguous 123 | end.x=a[cnt].x,end.y=a[cnt].y,end.id=a[cnt].id; | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:23:16: note: 'node end' 23 | }a[maxn],start,end; | ^~~ a.cc:145:21: error: reference to 'end' is ambiguous 145 | if(start.y==end.y||start.x==end.x) | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:23:16: note: 'node end' 23 | }a[maxn],start,end; | ^~~ a.cc:145:37: error: reference to 'end' is ambiguous 145 | if(start.y==end.y||start.x==end.x) | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:23:16: note: 'node end' 23 | }a[maxn],start,end; | ^~~
s401737043
p03718
C++
#include<iostream> #include<ctime> #include<cstdlib> #include<cstdio> #include<cmath> #include<climits> #include<cstring> #include<iomanip> #include<string> #include<bitset> #include<unordered_map> #include<unordered_set> #include<set> #include<vector> #include<map> #include<queue> #include<stack> #include<deque> #include<algorithm> #include<functional> #include<chrono> #include<windows.h> #include<direct.h> #include<random> #include<sstream> #define y0 asdahsdlkahsdad #define y1 aasdfasdfasdf #define yn askfhwqriuperikldjk #define j1 assdgsdgasghsf #define taskname "LotusLeaves" //#define BeztDonkey typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; const int maxV = 202, maxE = 1e4, maxC = maxV; struct TEdge { int u, v, cf; } e[maxE << 1]; vector<int> adj[maxV]; int trace[maxV], h, w, s, t, E, flowVal; inline void AddEdge(int u, int v, int c) { adj[u].push_back(E); e[E++] = {u, v, c}; adj[v].push_back(E); e[E++] = {v, u, c}; } void Inp() { cin >> h >> w; s = h + w; t = s + 1; E = 0; for (int i = 0; i < h; ++i) { string tmp; cin >> tmp; for (int j = 0; j < w; ++j) if (tmp[j] == 'o') AddEdge(i, j + h, 1); else if (tmp[j] == 'S') AddEdge(s, i, maxC), AddEdge(s, j + h, maxC); else if (tmp[j] == 'T') AddEdge(i, t, maxC), AddEdge(j + h, t, maxC); } } inline bool FindAumentingPath() { memset(trace, -1, sizeof trace); queue<int> q({s}); trace[s] = -2; while (!q.empty()) { int u = q.front(), v; q.pop(); for (int i : adj[u]) { if (e[i].cf == 0 || trace[v = e[i].v] != -1) continue; trace[v] = i; if (v == t) return 1; q.push(v); } } return 0; } inline void AugmentFlow() { int del = maxC, i; for (int u = t; (i = trace[u]) != -2; u = e[i].u) del = min(del, e[i].cf); for (int u = t; (i = trace[u]) != -2; u = e[i].u) e[i].cf -= del, e[i ^ 1].cf += del; flowVal += del; } void Solve() { flowVal = 0; while (FindAumentingPath()) AugmentFlow(); cout << (flowVal >= maxC ? -1 : flowVal); } int main() { #ifdef BeztDonkey auto start = chrono::steady_clock::now(); #endif ios_base::sync_with_stdio(0); cin.tie(0); //freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); Inp(); Solve(); #ifdef BeztDonkey auto end = chrono::steady_clock::now(); cerr << "In milliseconds : " << chrono::duration_cast<chrono::milliseconds>(end - start).count(); cerr << '\n' << "In seconds : " << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n'; #endif return 0; }
a.cc:22:9: fatal error: windows.h: No such file or directory 22 | #include<windows.h> | ^~~~~~~~~~~ compilation terminated.
s715207804
p03718
C++
#include <iostream> #include <string> #include <array> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; using namespace std; #ifdef INPUT #include <sstream> stringstream input(R"( 3 2 acp ae )"); #define cin input #endif bool bfs(int rGraph[202][202], int s, int t, int parent[]) { using namespace std; bool visited[202] = {}; queue <int> q; q.push(s); visited[s] = true; parent[s] = -1; while (!q.empty()) { int u = q.front(); q.pop(); for (int v = 0; v < 202; v++) { if (visited[v] == false && rGraph[u][v] > 0) { q.push(v); parent[v] = u; visited[v] = true; } } } return (visited[t] == true); } int fordFulkerson(int graph[202][202], int s, int t) { int u, v; int rGraph[202][202]; for (u = 0; u < 202; u++) { for (v = 0; v < 202; v++) { rGraph[u][v] = graph[u][v]; } } int parent[202]; int max_flow = 0; while (bfs(rGraph, s, t, parent)) { int path_flow = INT_MAX; for (v = t; v != s; v = parent[v]) { u = parent[v]; path_flow = min(path_flow, rGraph[u][v]); } for (v = t; v != s; v = parent[v]) { u = parent[v]; rGraph[u][v] -= path_flow; rGraph[v][u] += path_flow; } max_flow += path_flow; } return max_flow; } int main() { int graph[202][202] = {}; int h, w; cin >> h >> w; int xs, ys, xt, yt; REP (i, h) { string s; cin >> s; REP (j, w) { switch (s[j]) { case 'o': graph[i][j + 100] = 1; graph[j + 100][i] = 1; break; case 'S': graph[200][j + 100] = 100000; graph[200][i] = 100000; xs = j; ys = i; break; case 'T': graph[i][201] = 100000; graph[j + 100][201] = 100000; xt = j; yt = j; break; } } } if (xs == xt || ys == yt) cout << -1 << endl; else cout << fordFulkerson(graph, 200, 201) << endl; return 0; }
a.cc: In function 'int fordFulkerson(int (*)[202], int, int)': a.cc:74:25: error: 'INT_MAX' was not declared in this scope 74 | int path_flow = INT_MAX; | ^~~~~~~ a.cc:13:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 12 | #include <iomanip> +++ |+#include <climits> 13 |
s730295973
p03718
C++
#include <iostream> #include <string> #include <array> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <algorithm> #include <cmath> #include <iomanip> #define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; using namespace std; #ifdef INPUT #include <sstream> stringstream input(R"( 3 2 acp ae )"); #define cin input #endif bool bfs(int rGraph[202][202], int s, int t, int parent[]) { using namespace std; bool visited[202]; memset(visited, 0, sizeof(visited)); queue <int> q; q.push(s); visited[s] = true; parent[s] = -1; while (!q.empty()) { int u = q.front(); q.pop(); for (int v = 0; v < 202; v++) { if (visited[v] == false && rGraph[u][v] > 0) { q.push(v); parent[v] = u; visited[v] = true; } } } return (visited[t] == true); } int fordFulkerson(int graph[202][202], int s, int t) { int u, v; int rGraph[202][202]; for (u = 0; u < 202; u++) { for (v = 0; v < 202; v++) { rGraph[u][v] = graph[u][v]; } } int parent[202]; int max_flow = 0; while (bfs(rGraph, s, t, parent)) { int path_flow = INT_MAX; for (v = t; v != s; v = parent[v]) { u = parent[v]; path_flow = min(path_flow, rGraph[u][v]); } for (v = t; v != s; v = parent[v]) { u = parent[v]; rGraph[u][v] -= path_flow; rGraph[v][u] += path_flow; } max_flow += path_flow; } return max_flow; } int main() { int graph[202][202] = {}; int h, w; cin >> h >> w; int xs, ys, xt, yt; REP (i, h) { string s; cin >> s; REP (j, w) { switch (s[j]) { case 'o': graph[i][j + 100] = 1; graph[j + 100][i] = 1; break; case 'S': graph[200][j + 100] = 100000; graph[200][i] = 100000; xs = j; ys = i; break; case 'T': graph[i][201] = 100000; graph[j + 100][201] = 100000; xt = j; yt = j; break; } } } if (xs == xt || ys == yt) cout << -1 << endl; else cout << fordFulkerson(graph, 200, 201) << endl; return 0; }
a.cc: In function 'bool bfs(int (*)[202], int, int, int*)': a.cc:37:5: error: 'memset' was not declared in this scope 37 | memset(visited, 0, sizeof(visited)); | ^~~~~~ a.cc:13:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 12 | #include <iomanip> +++ |+#include <cstring> 13 | a.cc: In function 'int fordFulkerson(int (*)[202], int, int)': a.cc:75:25: error: 'INT_MAX' was not declared in this scope 75 | int path_flow = INT_MAX; | ^~~~~~~ a.cc:13:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 12 | #include <iomanip> +++ |+#include <climits> 13 |
s023235225
p03718
C++
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #define fo(i,a,b) for(i=a;i<=b;i++) #define min(x,y) ((x)<(y)?(x):(y)) using namespace std; const int maxn=3e6+5; int fi[maxn],ne[maxn*2],dui[maxn*2],dui1[maxn*2],qc[maxn]; int a[105][105],de[20005],h[maxn]; char s[105]; int i,j,k,l,m,n,x,y,now,p,be,ed,ans; bool bq; void add(int x,int y,int z){ if (fi[x]==0) fi[x]=++now; else ne[qc[x]]=++now; dui[now]=y; dui1[now]=z; qc[x]=now; } bool bfs(){ memset(de,255,sizeof(de)); de[be]=0; h[1]=be; i=1; j=0; while (i>j){ x=h[++j]; for(int k=fi[x];k;k=ne[k]){ if (de[dui[k]]!=-1 || dui1[k]==0) continue; de[dui[k]]=de[x]+1; h[++i]=dui[k]; } } if (de[ed]==-1) return false; else return true; } int dinic(int x,int w){ int i=fi[x],now=0,p; if (x==ed) return w; for(;i;i=ne[i]){ if (dui1[i]==0 || de[dui[i]]!=de[x]+1) continue; p=dinic(dui[i],min(w-now,dui1[i])); if (p){ dui1[i]-=p; dui1[i xor 1]+=p; now+=p; } } return now; } int main(){ // freopen("074f.in","r",stdin); scanf("%d%d",&n,&m); fo(i,1,n){ scanf("%s",&s); fo(j,0,m-1){ if (s[j]=='.') continue; a[i][j+1]=++p; if (s[j]=='S') be=p; if (s[j]=='T') ed=p; } } now=1; fo(i,1,n) fo(j,1,m) if (a[i][j]>0 && a[i][j]!=ed){ fo(k,1,m) if (a[i][k]>0 && a[i][k]!=a[i][j] && a[i][k]!=be){ add(a[i][j]+p,a[i][k],1234567); if (a[i][j]==be && a[i][k]==ed){ printf("-1\n"); return 0; } } fo(k,1,n) if (a[k][j]>0 && a[k][j]!=a[i][j] && a[k][j]!=be){ add(a[i][j]+p,a[k][j],1234567); if (a[i][j]==be && a[k][j]==ed){ printf("-1\n"); return 0; } } } fo(i,1,p){ if (i==be || i==ed) add(i,i+p,1234567); else add(i,i+p,1); add(i+p,i,0); } ed=ed+p; while (bfs()) ans=ans+dinic(be,1234567); printf("%d\n",ans); return 0; } --------------------- 本文来自 Fate_Zero_Saber 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/Fate_Zero_Saber/article/details/79415307?utm_source=copy
a.cc:87:1: error: expected unqualified-id before '--' token 87 | --------------------- | ^~
s144528799
p03718
Java
import java.util.*; public class edge { int to; int cap; int rev;//逆辺にアクセスする edge(int to,int cap,int rev){ this.to =to; this.cap =cap; this.rev =rev; } } public class Main { static final int INF=Integer.MAX_VALUE; static boolean[] used; static int flow; static int V;//頂点 static int E;//辺 static int H; static int W; static int s; static int t; static char[][]S; static List<List<edge>> G;//listの二重構造で隣接リスト実現 public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc= new Scanner(System.in); H= sc.nextInt(); W= sc.nextInt(); V= H+W+2; s= 0; t=H+W+1; S= new char[H][W]; G= new ArrayList<>(); for(int i=0;i<V;i++)G.add(new ArrayList<>()); for(int i=0;i<H;i++) S[i]= sc.next().toCharArray(); sc.close(); if(check(S)){//sからtまでひと飛びで行ける位置関係なら−1 System.out.println(-1); } else{ //Gの作成。S[]が0originだから、x,yそれぞれ+1することに注意 for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ char com= S[i][j]; int y=i+1; int x=H+ j+1; switch(com){ case '.': break; case 'o'://無向グラフだから双方向に繋ぐ addedge(y,x,1); addedge(x,y,1); break; case 'S': addedge(s,y,INF); addedge(s,x,INF); break; case 'T': addedge(y,t,INF); addedge(x,t,INF); break; } } } int ans= max_flow(s,t); System.out.println(ans); } } static void addedge(int from,int to,int cap){ G.get(from).add(new edge(to,cap,G.get(to).size())); //同時に逆辺も辿れるようにするため、に双方向に紐をつける。 G.get(to).add(new edge(from,0,G.get(from).size()-1)); } static boolean check(char[][]S){ boolean res=false; int Sx= 0; int Sy= 0; int Tx= 0; int Ty= 0; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ char com= S[i][j]; if(com=='S'){ Sy=i; Sx=j; } if(com=='T'){ Ty= i; Tx= j; } } } if(Sy ==Ty ||Sx== Tx)res= true; return res; } static int dfs(int v,int t,int f){ if(v == t)return f;//tまでたどり着いた used[v] = true; for(int i=0;i<G.get(v).size();i++){ edge e =G.get(v).get(i); if(used[e.to] != true && e.cap >0){ int d= dfs(e.to,t,Math.min(f, e.cap)); //min(f,e.cap)はまだ流す量を決めている段階。暫定の流量 if(d>0){//tまでたどり着いた(流せる)時 //v==tのreturn fを受けて、ここで初めてf(=d)を流す e.cap-= d; G.get(e.to).get(e.rev).cap += d;//直接逆辺のcを変化させて、 return d;//各辺でdを流すために戻る。  } } } return 0; } static int max_flow(int s,int t) { int flow= 0; while(true){ used =new boolean[V]; int f= dfs(s,t,INF); if(f == 0){ //if(arrive= false)return -1; return flow;//if(もうこれ以上流せない)return } flow +=f; } } }
Main.java:3: error: class edge is public, should be declared in a file named edge.java public class edge { ^ 1 error
s248687773
p03718
Java
public class edge { int to; int cap; int rev;//逆辺にアクセスする edge(int to,int cap,int rev){ this.to =to; this.cap =cap; this.rev =rev; } } public class Main { static final int INF=Integer.MAX_VALUE; static boolean[] used; static int flow; static int V;//頂点 static int E;//辺 static int H; static int W; static int s; static int t; static char[][]S; static List<List<edge>> G;//listの二重構造で隣接リスト実現 public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc= new Scanner(System.in); H= sc.nextInt(); W= sc.nextInt(); V= H+W+2; s= 0; t=H+W+1; S= new char[H][W]; G= new ArrayList<>(); for(int i=0;i<V;i++)G.add(new ArrayList<>()); for(int i=0;i<H;i++) S[i]= sc.next().toCharArray(); sc.close(); if(check(S)){//sからtまでひと飛びで行ける位置関係なら−1 System.out.println(-1); } else{ //Gの作成。S[]が0originだから、x,yそれぞれ+1することに注意 for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ char com= S[i][j]; int y=i+1; int x=H+ j+1; switch(com){ case '.': break; case 'o'://無向グラフだから双方向に繋ぐ addedge(y,x,1); addedge(x,y,1); break; case 'S': addedge(s,y,INF); addedge(s,x,INF); break; case 'T': addedge(y,t,INF); addedge(x,t,INF); break; } } } int ans= max_flow(s,t); System.out.println(ans); } } static void addedge(int from,int to,int cap){ G.get(from).add(new edge(to,cap,G.get(to).size())); //同時に逆辺も辿れるようにするため、に双方向に紐をつける。 G.get(to).add(new edge(from,0,G.get(from).size()-1)); } static boolean check(char[][]S){ boolean res=false; int Sx= 0; int Sy= 0; int Tx= 0; int Ty= 0; for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ char com= S[i][j]; if(com=='S'){ Sy=i; Sx=j; } if(com=='T'){ Ty= i; Tx= j; } } } if(Sy ==Ty ||Sx== Tx)res= true; return res; } static int dfs(int v,int t,int f){ if(v == t)return f;//tまでたどり着いた used[v] = true; for(int i=0;i<G.get(v).size();i++){ edge e =G.get(v).get(i); if(used[e.to] != true && e.cap >0){ int d= dfs(e.to,t,Math.min(f, e.cap)); //min(f,e.cap)はまだ流す量を決めている段階。暫定の流量 if(d>0){//tまでたどり着いた(流せる)時 //v==tのreturn fを受けて、ここで初めてf(=d)を流す e.cap-= d; G.get(e.to).get(e.rev).cap += d;//直接逆辺のcを変化させて、 return d;//各辺でdを流すために戻る。  } } } return 0; } static int max_flow(int s,int t) { int flow= 0; while(true){ used =new boolean[V]; int f= dfs(s,t,INF); if(f == 0){ //if(arrive= false)return -1; return flow;//if(もうこれ以上流せない)return } flow +=f; } } }
Main.java:1: error: class edge is public, should be declared in a file named edge.java public class edge { ^ Main.java:30: error: cannot find symbol static List<List<edge>> G;//list????????????? ^ symbol: class List location: class Main Main.java:30: error: cannot find symbol static List<List<edge>> G;//list????????????? ^ symbol: class List location: class Main Main.java:34: error: cannot find symbol Scanner sc= new Scanner(System.in); ^ symbol: class Scanner location: class Main Main.java:34: error: cannot find symbol Scanner sc= new Scanner(System.in); ^ symbol: class Scanner location: class Main Main.java:45: error: cannot find symbol G= new ArrayList<>(); ^ symbol: class ArrayList location: class Main Main.java:46: error: cannot find symbol for(int i=0;i<V;i++)G.add(new ArrayList<>()); ^ symbol: class ArrayList location: class Main 7 errors
s364251088
p03718
C++
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #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; typedef pair<ll,int> pli; 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} ; struct edge{int to;int cap;int rev;}; struct Dinic{ private: int n; vector<vector<edge>> v; vector<int> dist,iter; public: Dinic(int sz):n(sz),v(sz),dist(sz),iter(sz){} void addedge(int from,int to,int cap){ int x=v[to].size(),y=v[from].size(); v[from].push_back({to,cap,x}); v[to].push_back({from,0,y}); } void bfs(int s){ fill(dist.begin(),dist.end(),-1); queue<int> q; dist[s]=0; q.push(s); while(q.size()){ int x=q.front();q.pop(); rep(i,v[x].size()){ edge &e=v[x][i]; if(e.cap>0&&dist[e.to]<0){ dist[e.to]=dist[x]+1; q.push(e.to); } } } } int dfs(int x,int t,int f){ if(x==t)return f; for(int& i=iter[x];i<(int)v[x].size();++i){ edge& e=v[x][i]; if(e.cap>0&&dist[x]<dist[e.to]){ int d=dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap-=d; v[e.to][e.rev].cap+=d; return d; } } } return 0; } int max_flow(int s,int t){ int flow=0; while(1){ bfs(s); if(dist[t]<0)return flow; fill(iter.begin(),iter.end(),0); int f; while((f=dfs(s,t,inf)>0)flow+=f; } } }; int main(){ int h,w; cin>>h>>w; Dinic dn(h+w+2); string s[h]; rep(i,h){ cin>>s[i]; rep(j,w){ if(s[i][j]=='S'){ dn.addedge(h+w, i, inf); dn.addedge(h+w, h+j, inf); } if(s[i][j]=='T'){ dn.addedge(i,h+w+1, inf); dn.addedge(h+j,h+w+1, inf); } if(s[i][j]=='o'){ dn.addedge(i, h+j, 1); dn.addedge(h+j, i, 1); } } } int ans=dn.max_flow(h+w, h+w+1); cout<<(ans>=inf?-1:ans)<<endl; return 0; }
a.cc: In member function 'int Dinic::max_flow(int, int)': a.cc:80:37: error: expected ')' before 'flow' 80 | while((f=dfs(s,t,inf)>0)flow+=f; | ^~~~ a.cc:80:18: note: to match this '(' 80 | while((f=dfs(s,t,inf)>0)flow+=f; | ^
s161843854
p03718
C++
#include<bits/stdc++.h> #include<iostream> #include<algorithm> #include<string> #include<map> #include<set> #include<vector> #include<string.h> #include<math.h> #include<stdio.h> #include<queue> #include<utility> #include<cstdio> #include<cstring> #include<new> #include<new.h> #include<float.h> #include<ctype.h> #include<cfloat> #include<cmath> #include<cctype> #include<errno.h> #include<cerrno> #include<memory> #include<memory.h> #include<assert.h> #include<cassert> #include<deque> #define fo(i,w,n) for(int i=(int) w;i<(int) n;i++) #define qui queue<int> #define vit vector<int> #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define prq priority_queue #define pii pair<int,int> #define mp make_pair #define sz size() #define em empty() #define ct continue #define ms multiset #define all(a) (a).begin(),(a).end() #define pf push_front #define ppf pop_front() using namespace std; int n,m,way=0,h[101][101]; char a[101][101]; bool used[202][101][101]; void dfs(int x,int y){ used[way][x][y]=1; fo(i,0,m){ if(a[x][i]=='T'){ way++; return; } if(!used[way][x][i]&&a[x][i]=='o')dfs(x,i); used[way][x][i]=0; } fo(i,0,n){ if(a[i][y]=='T'){ way++; return; } if(!used[way][i][y]&&a[i][y]=='o')dfs(i,y); used[way][i][y]=0; } } int main() { int s1,s2,t1,t2,w=0,ans=0; cin>>n>>m; fo(i,0,n){ cin>>a[i]; fo(j,0,m){ if(a[i][j]=='S')s1=i,s2=j; if(a[i][j]=='T')t1=i,t2=j; } } if(s1==t1||s2==t2){ cout<<"-1"<<endl; return 0; } dfs(s1,s2); fo(i,0,n) fo(j,0,m) fo(k,0,way)if(used[k][i][j])h[i][j]++; while(w<way){ ans++; int fd=0,o,p; fo(i,0,n) fo(j,0,m){ if(h[i][j]>fd){ fd=h[i][j]; o=i; p=j; } } w+=fd; h[o][p]=0; fo(i,0,way) fo(j,0,n) fo(k,0,m)if(used[i][k][j]&&used[i][o][p])h[j][k]--; } cout<<ans<<endl; return 0; }
a.cc:16:9: fatal error: new.h: No such file or directory 16 | #include<new.h> | ^~~~~~~ compilation terminated.
s873371556
p03718
C++
use std::io::*; use std::str::FromStr; #[allow(dead_code)] fn read<T: FromStr>() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } type Weight = i32; #[allow(dead_code)] #[derive(Clone, Debug, Eq, PartialEq)] struct Edge { index: usize, src: usize, dest: usize, weight: Weight, } #[allow(dead_code)] impl Edge { fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge { Edge { index: index, src: src, dest: dest, weight: weight, } } } impl std::cmp::Ord for Edge { fn cmp(&self, other: &Self) -> std::cmp::Ordering { (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest)) } } impl std::cmp::PartialOrd for Edge { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { Some(self.cmp(other)) } } type Edges = Vec<Edge>; type Graph = Vec<Edges>; #[allow(dead_code)] fn graph_new(n: usize) -> Graph { vec![vec![]; n] } use std::collections::VecDeque; // index ^ 1 is reverse edge #[allow(dead_code)] fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) { graph[src].push(Edge::new(*index, src, dest, weight)); *index += 1; graph[dest].push(Edge::new(*index, dest, src, 0)); *index += 1; } #[allow(dead_code)] fn augment( g: &Graph, capacity: &mut Vec<Weight>, level: &Vec<usize>, finished: &mut Vec<bool>, from: usize, t: usize, cur: Weight, ) -> Weight { if from == t || cur == 0 { return cur; } if finished[from] { return 0; } for edge in g[from].iter() { let to = edge.dest; if level[to] != level[from] + 1 { continue; } let ncur = std::cmp::min(cur, capacity[edge.index]); let f = augment(g, capacity, level, finished, to, t, ncur); if f > 0 { capacity[edge.index] -= f; capacity[edge.index ^ 1] += f; return f; } } finished[from] = true; 0 } #[allow(dead_code)] fn max_flow(g: &Graph, e: usize, s: usize, t: usize) -> Weight { let n = g.len(); let mut capacity: Vec<Weight> = vec![0; e]; for from in 0..n { for edge in g[from].iter() { capacity[edge.index] += edge.weight; } } let mut ans = 0; loop { let mut level = vec![usize::max_value(); n]; level[s] = 0; let mut que = VecDeque::<usize>::new(); que.push_back(s); while let Some(from) = que.pop_front() { if from == t { break; } for edge in g[from].iter() { let to = edge.dest; if capacity[edge.index] > 0 && level[to] == usize::max_value() { que.push_back(to); level[to] = level[from] + 1; } } } let mut finished = vec![false; n]; let mut end = true; loop { let f = augment( g, &mut capacity, &level, &mut finished, s, t, Weight::max_value(), ); if f == 0 { break; } ans += f; end = false; } if end { break; } } ans } fn main() { let h = read::<usize>(); let w = read::<usize>(); let mut field = vec![vec![]; h]; for y in 0..h { field[y] = read::<String>().chars().collect::<Vec<char>>(); } let in_node = |y: usize, x: usize| y * w + x; let out_node = |y: usize, x: usize| y * w + x + h * w; let graph_size = || h * w * 2; let mut g = graph_new(graph_size()); let mut e = 0; let mut s = 0; let mut t = 0; for y in 0..h { for x in 0..w { if field[y][x] == '.' { continue; } if field[y][x] == 'S' { s = in_node(y, x); } if field[y][x] == 'T' { t = out_node(y, x); } add_uni_edge(&mut g, &mut e, out_node(y, x), in_node(y, x), 1); for ny in 0..h { if y == ny || field[ny][x] == '.' { continue; } add_uni_edge(&mut g, &mut e, in_node(y, x), out_node(ny, x), 10000); } for nx in 0..w { if x == nx || field[y][nx] == '.' { continue; } add_uni_edge(&mut g, &mut e, in_node(y, x), out_node(y, nx), 10000); } } } let mut ans = max_flow(&g, e, s, t); if s % w == t % w || s / w == t / w { ans = -1; } println!("{}", ans); }
a.cc:4:2: error: invalid preprocessing directive #[ 4 | #[allow(dead_code)] | ^ a.cc:18:2: error: invalid preprocessing directive #[ 18 | #[allow(dead_code)] | ^ a.cc:19:2: error: invalid preprocessing directive #[ 19 | #[derive(Clone, Debug, Eq, PartialEq)] | ^ a.cc:26:2: error: invalid preprocessing directive #[ 26 | #[allow(dead_code)] | ^ a.cc:49:2: error: invalid preprocessing directive #[ 49 | #[allow(dead_code)] | ^ a.cc:55:2: error: invalid preprocessing directive #[ 55 | #[allow(dead_code)] | ^ a.cc:63:2: error: invalid preprocessing directive #[ 63 | #[allow(dead_code)] | ^ a.cc:96:2: error: invalid preprocessing directive #[ 96 | #[allow(dead_code)] | ^ a.cc:100:17: error: too many decimal points in number 100 | for from in 0..n { | ^~~~ a.cc:152:14: error: too many decimal points in number 152 | for y in 0..h { | ^~~~ a.cc:162:14: error: too many decimal points in number 162 | for y in 0..h { | ^~~~ a.cc:163:18: error: too many decimal points in number 163 | for x in 0..w { | ^~~~ a.cc:174:23: error: too many decimal points in number 174 | for ny in 0..h { | ^~~~ a.cc:180:23: error: too many decimal points in number 180 | for nx in 0..w { | ^~~~ a.cc:1:1: error: 'use' does not name a type 1 | use std::io::*; | ^~~ a.cc:2:1: error: 'use' does not name a type 2 | use std::str::FromStr; | ^~~ a.cc:5:1: error: 'fn' does not name a type 5 | fn read<T: FromStr>() -> T { | ^~ a.cc:17:1: error: 'type' does not name a type; did you mean 'typeof'? 17 | type Weight = i32; | ^~~~ | typeof a.cc:21:5: error: 'index' does not name a type 21 | index: usize, | ^~~~~ a.cc:27:6: error: expected initializer before 'Edge' 27 | impl Edge { | ^~~~ a.cc:37:1: error: 'impl' does not name a type 37 | impl std::cmp::Ord for Edge { | ^~~~ a.cc:42:1: error: 'impl' does not name a type 42 | impl std::cmp::PartialOrd for Edge { | ^~~~ a.cc:47:1: error: 'type' does not name a type; did you mean 'typeof'? 47 | type Edges = Vec<Edge>; | ^~~~ | typeof a.cc:48:1: error: 'type' does not name a type; did you mean 'typeof'? 48 | type Graph = Vec<Edges>; | ^~~~ | typeof a.cc:50:1: error: 'fn' does not name a type 50 | fn graph_new(n: usize) -> Graph { | ^~ a.cc:53:1: error: 'use' does not name a type 53 | use std::collections::VecDeque; | ^~~ a.cc:56:1: error: 'fn' does not name a type 56 | fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) { | ^~ a.cc:64:1: error: 'fn' does not name a type 64 | fn augment( | ^~ a.cc:97:1: error: 'fn' does not name a type 97 | fn max_flow(g: &Graph, e: usize, s: usize, t: usize) -> Weight { | ^~ a.cc:148:1: error: 'fn' does not name a type 148 | fn main() { | ^~
s249241462
p03718
C
#include<bits/stdc++.h> using namespace std; const int INF=0x3f3f3f3f; int H,W; char str[102]; int Sx,Sy,Tx,Ty; int fk[101][101]; int h[100001],nxt[100001],to[100001],w[100001],tot=-1; void ins(int x,int y,int z){nxt[++tot]=h[x];to[tot]=y;w[tot]=z;h[x]=tot;} void insw(int x,int y,int z1,int z2){ins(x,y,z1);ins(y,x,z2);} int lv[100001],que[100001],l,r; bool lvl(){ memset(lv,0,sizeof lv); lv[que[l=r=1]=0]=1; while(l<=r){ int u=que[l++]; for(int i=h[u];~i;i=nxt[i]) if(w[i]) if(!lv[to[i]]) lv[to[i]]=lv[u]+1, que[++r]=to[i]; } return lv[2*H*W+H+W+1]!=0; } int flow(int u,int f){ // if(u==0) printf("u=S "); // else if(u==2*H*W+H+W+1) printf("u=T "); // else if(u<=2*H*W) printf("u=%d,%d,%d ",((u+1)/2-1)/W+1,((u+1)/2-1)%W+1,u%2==0); // else if(u<=2*H*W+H) printf("u=Row#%d ",u-2*H*W); // else printf("u=Col#%d ",u-2*H*W-H); // printf("%d\n",f); if(u==2*H*W+H+W+1) return f; int sum=0,d; for(int i=h[u];~i;i=nxt[i]) if(lv[to[i]]>lv[u]&&w[i]){ d=flow(to[i],min(f,w[i])); sum+=d, f-=d; w[i]-=d, w[i^1]+=d; if(!f) break; } return sum; } int Dinic(){ int ans=0; while(lvl()) ans+=flow(0,INF); return ans; } int main(){ memset(h,-1,sizeof h); scanf("%d%d",&H,&W); for(int i=1;i<=H;++i){ scanf("%s",str+1); for(int j=1;j<=W;++j){ if(str[j]=='o') fk[i][j]=1; if(str[j]=='S') Sx=i, Sy=j; if(str[j]=='T') Tx=i, Ty=j; } } if(Sx==Tx||Sy==Ty) return 0*puts("-1"); for(int i=1;i<=H;++i) for(int j=1;j<=W;++j) if(fk[i][j]){ int id = 2*((i-1)*W+j); int Rid = 2*H*W+i; int Cid = 2*H*W+H+j; insw(id-1,id,1,0); insw(Rid,id-1,INF,0); insw(Cid,id-1,INF,0); insw(id,Rid,INF,0); insw(id,Cid,INF,0); } int RidS = 2*H*W+Sx; int CidS = 2*H*W+H+Sy; int RidT = 2*H*W+Tx; int CidT = 2*H*W+H+Ty; insw(0,RidS,INF,INF); insw(0,CidS,INF,INF); insw(RidT,2*H*W+H+W+1,INF,INF); insw(CidT,2*H*W+H+W+1,INF, INF); printf("%d",Dinic()); return 0; }
main.c:1:9: fatal error: bits/stdc++.h: No such file or directory 1 | #include<bits/stdc++.h> | ^~~~~~~~~~~~~~~ compilation terminated.
s898704870
p03718
C
/* cat <<EOF >mistaken-paste */ #pragma GCC diagnostic ignored "-Wincompatible-pointer-types" #define _USE_MATH_DEFINES #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include <math.h> #include <time.h> #define BIG 2000000007 #define VERYBIG 200000000000007LL #define MOD 1000000007 typedef uint64_t ull; typedef int64_t sll; #define N_MAX 2000 #define M_MAX 200000 #ifdef __cplusplus #include <queue> #include <stack> // #include <tuple> #include <set> #include <map> // using namespace std; // HELL using std::queue; using std::priority_queue; using std::stack; // using std::tuple; using std::set; using std::map; using std::vector; using std::greater; using std::pair; #endif typedef struct { int32_t a; int32_t b; } hw; typedef struct { sll a; sll b; } hwll; typedef struct { hwll a; hwll b; } linell; typedef struct { ull s; ull t; int32_t c; } struct_a; typedef struct { int32_t from; int32_t to; sll cost; } struct_b; const hw vector8[8] = { {-1, -1}, {-1, 0}, {-1, +1}, { 0, -1}, { 0, +1}, {+1, -1}, {+1, 0}, {+1, +1} }; ull n, m; ull h, w; ull k; ull q; ull vua, vub, vuc, vud, vue, vuf; sll vsa, vsb, vsc, vsd, vse, vsf; long double vra, vrb, vrc; double vda, vdb, vdc; size_t slen; size_t tlen; char ch, dh; ull umin (ull x, ull y) { return (x < y) ? x : y; } ull umax (ull x, ull y) { return (x > y) ? x : y; } sll smin (sll x, sll y) { return (x < y) ? x : y; } sll smax (sll x, sll y) { return (x > y) ? x : y; } ull gcd (ull x, ull y) { if (x < y) { return gcd(y, x); } else if (y == 0) { return x; } else { return gcd(y, x % y); } } ull bitpow (ull a, ull x, ull modulo) { ull result = 1; while (x) { if (x & 1) { result *= a; result %= modulo; } x /= 2; a = (a * a) % modulo; } return result; } ull divide (ull a, ull b, ull modulo) { return (a * bitpow(b, modulo - 2, modulo)) % modulo; } ull udiff (ull a, ull b) { if (a >= b) { return a - b; } else { return b - a; } } sll sdiff (sll a, sll b) { if (a >= b) { return a - b; } else { return b - a; } } void printUquotient (ull left, ull right) { const int32_t digits = 20; printf("%llu.", left / right); left %= right; for (int32_t i = 0; i < digits; i++) { left *= 10; printf("%1d", left / right); left %= right; } puts(""); return; } void printSquotient (sll left, sll right) { if (left * right < 0) putchar('-'); printUquotient(sdiff(left, 0), sdiff(right, 0)); return; } int bitcount (ull n) { int result = 0; while (n) { if (n & 1) result++; n /= 2; } return result; } #ifdef __cplusplus bool setfind (set<ull> s, ull x) { return (s.find(x) != s.end()); } #endif sll dist[N_MAX]; struct_b path[M_MAX * 2]; ull a[N_MAX]; // ull a[M_MAX]; // sll a[N_MAX]; // ull a[N_MAX][N_MAX]; // ull a[M_MAX][M_MAX]; // sll a[N_MAX][N_MAX]; ull b[N_MAX]; // ull b[M_MAX]; // sll b[N_MAX]; // ull c[N_MAX]; // sll c[M_MAX]; // char c[N_MAX]; // char s[N_MAX + 1]; char s[N_MAX + 1][N_MAX + 1]; // char s[N_MAX + 1][M_MAX + 1]; // char t[N_MAX + 1]; ull alphabets[26]; // ull blphabets[26]; // char alphabets[26]; ull dp[N_MAX + 1]; // sll dp[N_MAX + 1]; // ull dp[N_MAX + 1][N_MAX + 1]; // sll dp[N_MAX + 1][N_MAX + 1]; // bool dp[N_MAX + 1]; // bool dp[N_MAX + 1][N_MAX + 1]; // bool dq[N_MAX]; hwll arr[N_MAX + 1]; // hwll arr[M_MAX]; hwll brr[N_MAX]; // sll dp[N_MAX + 1]; // ull color[N_MAX]; // set<sll> children[N_MAX]; // set<sll> leaf[N_MAX]; double distance (sll x1, sll y1, sll x2, sll y2) { double xdist2, ydist2, origindist, dist; xdist2 = (x1 - x2) * (x1 - x2); ydist2 = (y1 - y2) * (y1 - y2); return sqrt(xdist2 + ydist2); } int32_t pullcomp (const void *left, const void *right) { ull l = *(ull*)left; ull r = *(ull*)right; if (l < r) { return -1; } if (l > r) { return +1; } return 0; } int32_t phwllABcomp (const void *left, const void *right) { hwll l = *(hwll*)left; hwll r = *(hwll*)right; if (l.a < r.a) { return -1; } if (l.a > r.a) { return +1; } if (l.b < r.b) { return -1; } if (l.b > r.b) { return +1; } return 0; } ull accp (ull a, ull p) { if (a == 0) { return 0; } if (a == 1) { return p; } return divide((MOD + bitpow(a, p, MOD) - 1) % MOD, a - 1, MOD); } typedef pair<ull, ull> P; // map<ull, ull> g[N_MAX * 2 + 2]; ull g[N_MAX][N_MAX]; bool visited[N_MAX]; ull dfs (ull now, ull goal, ull f) { if (now == goal) return f; // sll i = g[now].size(); // while (i--) { // for (P &edge : g[now]) { for (sll v = 0; v < h + w + 2; v++) { // P &edge = g[now][i]; // ull v = edge.first; // ull num = edge.second; ull num = g[now][v]; if (num == 0) continue; // if (visited.find(v) != visited.end()) continue; if (visited[v]) continue; // set<ull> nv = visited; // nv.insert(v); visited[v] = true; ull maybe = dfs(v, goal, umin(f, num)); visited[v] = false; if (maybe > 0) { // edge.second -= maybe; g[now][v] -= maybe; // auto gv = g[v].find(now); // if (gv == g[v].end()) { // g[v].insert(P(now, maybe)); // } else { // (*gv).second += maybe; // } g[v][now] += maybe; return maybe; } } return 0; } ull flow (ull s, ull t) { ull f; ull res = 0; // set<ull> v1; // v1.insert(s); while (true) { for (sll i = 0; i < h + w + 2; i++) visited[i] = false; visited[s] = true; f = dfs(s, t, BIG); if (!f) break; res += f; } return res; } ull solve () { sll i, j, ki; // ull result = 0; sll result = 0; // double result = 0; // ull maybe = 0; sll maybe = 0; // ull sum = 0; sll sum = 0; ull item; ull *dpcell; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { switch (s[i][j]) { case 'S': // g[h + w].insert(P(i, BIG)); // g[h + w].insert(P(h + j, BIG)); g[h + w][i] = g[h + w][h + j] = BIG; break; case 'T': // g[i].insert(P(h + w + 1, BIG)); // g[h + j].insert(P(h + w + 1, BIG)); g[i][h + w + 1] = g[h + j][h + w + 1] = BIG; break; case 'o': // g[i].insert(P(h + j, 1)); // g[h + j].insert(P(i, 1)); g[i][h + j] = g[h + j][i] = 1; break; } } } result = flow(h + w, h + w + 1); if (result >= BIG) goto fail; printf("%llu\n", result); // printf("%.12lf\n", (double)result); // puts(s); return 0; success: puts("YES"); // puts("Yes"); // printf("%llu\n", result); // puts("0"); // puts("First"); return 0; fail: // puts("NO"); // puts("No"); // puts("0"); puts("-1"); // puts("-1 -1 -1"); // puts("Second"); return 1; } int32_t main (void) { int32_t i, j; int32_t x, y; // scanf("%lf", &vda, &vdb); // scanf("%lld%lld%lld%lld", &vsa, &vsb, &vsc, &vsd); // scanf("%llu%llu", &vua, &vub, &vuc, &vud); scanf("%llu%llu", &h, &w); // scanf("%*llu%*llu"); // scanf("%llu%llu", &n, &m); // scanf("%llu", &k, &n); // scanf("%llu%llu", &vua, &vub, &vuc, &vud, &vue, &vuf); // scanf("%lld%lld", &vsa, &vsb, &vsc); // scanf("%s", s); // scanf("%s", t); // scanf("%llu", &m); // scanf("%llu", &q); // for (i = 0; i < n; i++) { // scanf("%lld", &a[i]); // scanf("%llu", &b[i]); // // a[i]--; // // b[i]--; // } // for (i = 0; i < n; i++) { // scanf("%llu", &b[i]); // } // for (i = 0; i < h; i++) { // for (j = 0; j < w; j++) { // scanf("%llu", &a[i][j]); // } // } for (i = 0; i < h; i++) { scanf("%s", &s[i]); } // scanf("%llu", &k); // scanf("%llu", &q); solve(); return 0; }
main.c:286:13: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token 286 | typedef pair<ull, ull> P; | ^
s716001040
p03718
C++
#define HMAX 102 #define WMAX 10210 10 .o...o..o. ....o..... ....oo.oo. ..oooo..o. ....oo.... ..o..o.... o..o....So o....T.... ....o..... ........oo
a.cc:3:1: error: expected unqualified-id before '.' token 3 | .o...o..o. | ^
s323451540
p03718
C++
#include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<ctime> #include<cstdlib> #define cmax(a,b) (a<(b)?a=(b),1:0) #define cmin(a,b) (a>(b)?a=(b),1:0) #define dmin(a,b) ((a)<(b)?(a):(b)) #define dmax(a,b) ((a)>(b)?(a):(b)) #define regsiter register #define CL fclose(stdin),fclose(stdout) namespace io { int F() { int n=0,F=1; char ch; while((ch=getchar())!='-'&&(ch<'0'||ch>'9')); ch=='-'?F=0:n=ch-'0'; while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0'; return F?n:-n; } long long G() { long long n=0,F=1; char ch; while((ch=getchar())!='-'&&(ch<'0'||ch>'9')); ch=='-'?F=0:n=ch-'0'; while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0'; return F?n:-n; } } char map[111][111]; struct edge { int to; int res; int next; }e[33333]; int pe=222; void insert(int a,int to,int cap) { e[pe]=(edge){to,cap,e[a].next}; e[a].next=pe++; } void addedge(int a,int to,int cap) { insert(a,to,cap); insert(to,a,0); } int s,t; int d[3333]; int q[3333],hq,tq; int vis[3333],pv; int cur[3333]; bool bfs() { for(q[hq=1]=t,tq=2,vis[t]=++pv,d[t]=0;hq!=tq;++hq) for(register int p=e[q[hq]].next;p;p=e[p].next) if(e[p^1].res&&vis[e[p].to]!=pv) vis[e[p].to]=pv,d[e[p].to]=d[q[hq]]+1,q[tq++]=e[p].to; return vis[s]==pv; } int dfs(int o,int min) { if(o==t||min==0)return min; int f=0,tmp; for(register int p;cur[o];cur[o]=e[cur[o]].next) { p=cur[o]; if(e[p].res&&d[e[p].to]==d[o]-1&&(tmp=dfs(e[p].to,dmin(min,e[p].res)))) { f+=tmp; e[p].res-=tmp; e[p^1].res+=tmp; min-=tmp; if(min==0)return f; } } return f; } int dinic() { int fl=0; while(bfs()) { for(register int i=1;i<=t;++i)cur[i]=e[i].next; fl+=dfs(s,0x7fffffff); } return fl; } int main() { int n=io::F(),m=io::F(); for(register int i=1;i<=n;++i)gets(map[i]+1); s=n+m+1,t=n+m+2; int sx,sy,tx,ty; for(register int i=1;i<=n;++i) for(register int j=1;j<=m;++j) { if(map[i][j]=='o')addedge(i,j+n,1),addedge(j+n,i,1); if(map[i][j]=='S')sx=i,sy=j; if(map[i][j]=='T')tx=i,ty=j; } addedge(s,sx,100000); addedge(s,sy+n,100000); addedge(tx,t,100000); addedge(ty+n,t,100000); int tmp=dinic(); if(tmp>=100000)puts("-1"); else printf("%d\n",tmp); return 0; }
a.cc: In function 'bool bfs()': a.cc:60:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 60 | for(register int p=e[q[hq]].next;p;p=e[p].next) | ^ a.cc: In function 'int dfs(int, int)': a.cc:69:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 69 | for(register int p;cur[o];cur[o]=e[cur[o]].next) | ^ a.cc: In function 'int dinic()': a.cc:88:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 88 | for(register int i=1;i<=t;++i)cur[i]=e[i].next; | ^ a.cc: In function 'int main()': a.cc:96:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 96 | for(register int i=1;i<=n;++i)gets(map[i]+1); | ^ a.cc:96:39: error: 'gets' was not declared in this scope; did you mean 'getw'? 96 | for(register int i=1;i<=n;++i)gets(map[i]+1); | ^~~~ | getw a.cc:99:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 99 | for(register int i=1;i<=n;++i) | ^ a.cc:100:34: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister] 100 | for(register int j=1;j<=m;++j) | ^
s751391317
p03718
Java
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Optional; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args){ Main main = new Main(); main.solveF(); } private void solveF() { Scanner sc = new Scanner(System.in); int H = sc.nextInt(); int W = sc.nextInt(); sc.nextLine(); final int SOURCE = 0; final int VERTEX_NUM = 2 + H + W; final int TARGET = VERTEX_NUM - 1; final int INF = Integer.MAX_VALUE / 3; // 1〜H : 行に対する移動 H+1〜H+W: 列に対する移動 Graph graph = new ArrayGraph(VERTEX_NUM); for (int r = 0; r < H; r++) { String line = sc.nextLine(); for (int c = 0; c < W; c++) { char asc = line.charAt(c); if (asc == 'o') { graph.link(r+1, H+1+c, 1); graph.link(H+1+c, r+1, 1); } else if (asc == 'S') { graph.link(SOURCE, r+1, INF); graph.link(SOURCE, H+1+c, INF); } else if (asc == 'T') { graph.link(r+1, TARGET, INF); graph.link(H+1+c, TARGET, INF); } } } FlowResolver fr = new IddfsFlowResolver(graph); int ans = fr.maxFlow(SOURCE, TARGET); if (ans >= INF) { System.out.println(-1); } else { System.out.println(ans); } } private void solveC() { Scanner sc = new Scanner(System.in); long H = sc.nextLong(); long W = sc.nextLong(); long W_3 = W /3; long W_31 = W_3 + 1; long H_3 = H / 3; long H_31 = H_3 + 1; long W_2 = W / 2; long W_21 = W_2 + 1; long H_2 = H / 2; long H_21 = H_2 + 1; List<Long> areaList = new ArrayList<Long>(); areaList.add(area(H * W_3, H * W_3, H * (W - 2 * W_3))); areaList.add(area(H * W_31, H * W_31, H * (W - 2 * W_31))); areaList.add(area(W * H_3, W * H_3, W * (H - 2 * H_3))); areaList.add(area(W * H_31, W * H_31, W * (H - 2 * H_31))); areaList.add(area(H * W_3, H_2 * (W - W_3), (H - H_2) * (W - W_3))); areaList.add(area(H * W_31, H_2 * (W - W_31), (H - H_2) * (W - W_31))); areaList.add(area(H * W_3, H_21 * (W - W_3), (H - H_21) * (W - W_3))); areaList.add(area(H * W_31, H_21 * (W - W_31), (H - H_21) * (W - W_31))); areaList.add(area(W * H_3, W_2 * (H - H_3), (W - W_2) * (H - H_3))); areaList.add(area(W * H_31, W_2 * (H - H_31), (W - W_2) * (H - H_31))); areaList.add(area(W * H_3, W_21 * (H - H_3), (W - W_21) * (H - H_3))); areaList.add(area(W * H_31, W_21 * (H - H_31), (W - W_21) * (H - H_31))); System.out.println(areaList.stream().min(Comparator.naturalOrder()).get()); } private long area(long a, long b, long c) { if (a <= b && b <= c) { return c - a; } if (a <= c && c <= b) { return b - a; } if (b <= a && a <= c) { return c - b; } if (b <= c && c <= a) { return a - b; } if (c <= a && a <= b) { return b - c; } if (c <= b && b <= a) { return a - c; } return 0; } private void solveD() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); List<Long> list = new ArrayList<>(); for (int i = 0; i < 3 * N; i++) { list.add(sc.nextLong()); } List<Long> maxSumList = getSumList(list, new PriorityQueue<>(Comparator.naturalOrder()), N); Collections.reverse(list); List<Long> minSumList = getSumList(list, new PriorityQueue<>(Comparator.reverseOrder()), N); List<Long> scoreList = new ArrayList<>(); for (int splitIndex = N; splitIndex <= 2 * N; splitIndex++) { scoreList.add(maxSumList.get(splitIndex - 1) - minSumList.get(3 * N - 1 - splitIndex)); } System.out.println(scoreList.stream().max(Comparator.naturalOrder()).get()); } private List<Long> getSumList(List<Long> list, PriorityQueue<Long> queue, int limitSize) { List<Long> sumList = new ArrayList<>(); long sum = 0L; for (long value : list) { queue.add(value); sum += value; if (queue.size() > limitSize) { sum -= queue.remove(); } sumList.add(sum); } return sumList; } interface Graph { void link(int from, int to, int cost); Optional<Integer> getCost(int from, int to); int getVertexNum(); } interface FlowResolver { int maxFlow(int from, int to); } /** * グラフの行列による実装 * 接点数の大きいグラフで使うとMLEで死にそう */ class ArrayGraph implements Graph { private Integer[][] costArray; private int vertexNum; public ArrayGraph(int n) { costArray = new Integer[n][]; for (int i = 0; i < n; i++) { costArray[i] = new Integer[n]; } vertexNum = n; } @Override public void link(int from, int to, int cost) { costArray[from][to] = new Integer(cost); } @Override public Optional<Integer> getCost(int from, int to) { return Optional.ofNullable(costArray[from][to]); } @Override public int getVertexNum() { return vertexNum; } } class BfsFlowResolver implements FlowResolver { private Graph graph; public BfsFlowResolver(Graph graph) { this.graph = graph; } public int maxFlow(int from, int to) { boolean finish = false; while (!finish) { Integer[] flows = new Integer[graph.getVertexNum()]; flows[from] = Integer.MAX_VALUE / 3; Integer[] froms = new Integer[graph.getVertexNum()]; boolean[] isPassed = new boolean[graph.getVertexNum()]; finish = false; while (!finish) { finish = true; for (int id = 0; id < graph.getVertexNum(); id++) { if (flows[id] != null) { if (flow(id, flows, froms)) { finish = false; } } } if (flows[to] != null) { int to_i = to; while (froms[to_i] != null) { graph.link(froms[to_i], to_i, graph.getCost(froms[to_i], to_i).get() - flows[to]); graph.link(to_i, froms[to_i], graph.getCost(to_i, froms[to_i]).orElse(0) + flows[to]); to_i = froms[to_i]; } finish = false; break; } } } int sum = 0; for (int id = 0; id < graph.getVertexNum(); id++) { sum += graph.getCost(to, id).orElse(0); } return sum; } public boolean flow(int from, Integer[] flows, Integer[] froms) { boolean change = false; for (int next = 0; next < graph.getVertexNum(); next++) { Optional<Integer> cost = graph.getCost(from, next); if (cost.orElse(0) > 0 && flows[next] == null) { int nextFlow = flows[from] < cost.get() ? flows[from] : cost.get(); flows[next] = nextFlow; froms[next] = from; change = true; } } return change; } } /** * IDDFS(反復深化深さ優先探索)による実装 * 終了条件は同じ節点を2度通らないDFS(深さ優先探索)で0が返ってきたとき * ほぼDinic法なので計算量はO(E*V*V)のはず (E:辺の数, V:節点の数) */ class IddfsFlowResolver implements FlowResolver { private Graph graph; public IddfsFlowResolver(Graph graph) { this.graph = graph; } /** * 最大フロー(最小カット)を求める * @param from 始点(source)のID * @param to 終点(target)のID * @return 最大フロー(最小カット) */ public int maxFlow(int from, int to) { int sum = 0; int limitDepth = 0; while (isExistFlow(from, to)) { boolean[] passed = new boolean[graph.getVertexNum()]; int currentFlow = flow(from, to,Integer.MAX_VALUE / 3, 0, limitDepth, passed); sum += currentFlow; if (currentFlow == 0) { limitDepth++; } } return sum; } /** * フローの実行 グラフの更新も行う * @param from 現在いる節点のID * @param to 終点(target)のID * @param current_flow ここまでの流量 * @param depth 探索(ネスト)の深さ * @param limitDepth 深さ制限 * @param passed 既に通った節点か否かを格納した配列 * @return 終点(target)に流した流量/戻りのグラフの流量 */ private int flow(int from, int to, int current_flow, int depth, int limitDepth, boolean[] passed) { passed[from] = true if (from == to) { return current_flow; } if (depth >= limitDepth) { return 0; } for (int id = 0; id < graph.getVertexNum(); id++) { if (passed[id]) { continue; } Optional<Integer> cost = graph.getCost(from, id); if (cost.orElse(0) > 0) { int nextFlow = current_flow < cost.get() ? current_flow : cost.get(); int returnFlow = flow(id, to, nextFlow, depth+1, limitDepth, passed); if (returnFlow > 0) { graph.link(from, id, cost.get() - returnFlow); graph.link(id, from, graph.getCost(id, from).orElse(0) + returnFlow); return returnFlow; } } } return 0; } /** * fromからtoに0以上の流量を流せるか調べる * @param from 始点(source)のID * @param to 終点(target)のID * @return 0以上流せればtrue */ private boolean isExistFlow(int from, int to) { boolean[] passed = new boolean[graph.getVertexNum()]; return search(from, to, passed); } /** * 今までに通ったことのない節点だけを調べるDFS(深さ優先探索) * 計算量は高々O(V)のはず (V:節点の数) * @param from 現在いる節点のID * @param to 終点(target)のID * @param passed 通過済みの節点IDにtrueが格納されている配列 * @return toに0以上流せればtrue */ private boolean search(int from, int to, boolean[] passed) { if (from == to) { return true; } passed[from] = true; for (int id = 0; id < graph.getVertexNum(); id++) { if (!passed[id] && graph.getCost(from, id).orElse(0) > 0 && search(id, to, passed)) { return true; } } return false; } } }
Main.java:278: error: ';' expected passed[from] = true ^ 1 error
s310792597
p03718
C++
#include "bits/stdc++.h" #include<unordered_map> #include<unordered_set> #include<random> #pragma warning(disable:4996) using namespace std; #define _GLIBCXX_DEBUG using namespace std; #define REP(i,n) for(int i=0;i<(int)n;++i) #define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i) #define ALL(c) (c).begin(), (c).end() //const int INF = 2147483647; //const long long int L_INF = 9223372036854775807; typedef int Weight; const Weight INF = 1e9; const Weight ZERO =0; struct Edge { int src, dst; Weight weight; int id; Edge(int src_, int dst_, Weight weight_, const int id_) : src(src_), dst(dst_), weight(weight_), id(id_) { } Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) { } Edge() :src(0), dst(0), weight(0) { } }; bool operator < (const Edge &e, const Edge &f) { return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!! e.src != f.src ? e.src < f.src : e.dst < f.dst; } typedef vector<Edge> Edges; typedef vector<Edges> Graph; typedef vector<Weight> Array; typedef vector<Array> Matrix; #define RESIDUE(s,t) (capacity[s][t]-flow[s][t]) //流量0の逆辺も張らないと正しく求まらないので注意 Weight maximumFlow(const Graph &ag, int s, int t) { Graph g(ag); for (int i = 0; i < ag.size(); ++i) { for (int j = 0; j < ag[i].size(); ++j) { int d = ag[i][j].dst; int s = ag[i][j].src; bool ok = false; for (int k = 0; k < ag[d].size(); ++k) { if (ag[d][k].src == s) { ok = true; break; } } if (!ok) { g[d].push_back(Edge(d, s, ZERO)); } } } int n = g.size(); Matrix flow(n, Array(n,ZERO)), capacity(n, Array(n,ZERO)); REP(u, n) FOR(e, g[u]) capacity[e->src][e->dst] =capacity[e->src][e->dst]+ e->weight; Weight total = ZERO; while (1) { queue<int> Q; Q.push(s); vector<int> prev(n, -1); prev[s] = s; while (!Q.empty() && prev[t] < 0) { int u = Q.front(); Q.pop(); FOR(e, g[u]) if (prev[e->dst] < 0 && RESIDUE(u, e->dst) > ZERO) { prev[e->dst] = u; Q.push(e->dst); } } if (prev[t] < 0)break; // prev[x] == -1 <=> t-side Weight inc = INF; for (int j = t; prev[j] != j; j = prev[j]){ auto v(RESIDUE(prev[j], j)); if (inc > v) { inc = v; } } for (int j = t; prev[j] != j; j = prev[j]) flow[prev[j]][j] =flow[prev[j]][j]+inc, flow[j][prev[j]] =flow[j][prev[j]]- inc;; total += inc; } return total; } int main() { int H,W;cin>>H>>W; vector<vector<int>>edges(H+W+2); vector<string>sts; for (int i = 0; i < H; ++i) { string st;cin>>st; sts.emplace_back(st); } int ans=0; Graph g(H+W+2); for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { char ch = sts[i][j]; vector<int>v; if (ch == 'o') { g[i].push_back(Edge(i,H+j,1)); g[H+j].push_back(Edge(H+j,i,1)); } else if (ch == 'S') { g[H+W].push_back(Edge(H+W,i,10000)); g[H+W].push_back(Edge(H+W,H+j,10000)); } else if (ch == 'T') { g[i].push_back(Edge(i,H+W+1,10099)); g[H+j].push_back(Edge(H+j,H+W+1,10099)); } } } ans=maximumFlow(g,H+W,H+W+1); if(ans>1000)ans=-1 cout<<ans<<endl; return 0; }
a.cc: In function 'int main()': a.cc:135:27: error: expected ';' before 'cout' 135 | if(ans>1000)ans=-1 | ^ | ; 136 | cout<<ans<<endl; | ~~~~
s757290157
p03718
C++
#include<stdio.h> #include<string.h> #include<iostream> #include<string> #include<algorithm> #include<vector> #include<map> #include<unordered_set> #include<unordered_map> #include<math.h> #include<queue> #include<functional> #include<limits.h> #include<string.h> #include<set> using namespace std; #define P pair<int,int> #define MOD 1000000007 #define INF 11234567890 #define in std::cin #define out std::cout #define rep(i,N) for(LL i=0;i<N;++i) typedef long long int LL;   const LL MAX_V = 20000; class Dinic { // 辺を表す構造体(行先、容量、逆辺) struct edge { LL to, cap, rev; };   std::vector<edge>G[MAX_V]; // グラフの隣接リスト表現 LL level[MAX_V]; // sからの距離 LL iter[MAX_V]; // どこまで調べ終わったか   public: // fromからtoへ向かう容量capの辺をグラフに追加する void add_edge(LL from, LL to, LL cap) { G[from].push_back({ to, cap, G[to].size() }); G[to].push_back({ from,0,G[from].size() - 1 }); }   // sからの最短距離をBFSで計算する void bfs(LL s) { memset(level, -1, sizeof(level)); std::queue<LL>que; level[s] = 0; que.push(s); while (!que.empty()) { LL v = que.front(); que.pop(); for (auto i : G[v]) { edge &e = i; if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[v] + 1; que.push(e.to); } } } }   // 増加パスをDFSで探す LL dfs(LL v, LL t, LL f) { if (v == t) { return f; } for (LL &i = iter[v]; i < G[v].size(); ++i) { edge &e = G[v][i]; if (e.cap > 0 && level[v] < level[e.to]) { LL d = dfs(e.to, t, std::min(f, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; }   // sからtへの最大流を求める LL max_flow(LL s, LL t) { LL flow = 0; while (true) { bfs(s); if (level[t] < 0) { return flow; } memset(iter, 0, sizeof(iter)); LL f; while ((f = dfs(s, t, INF)) > 0) { flow += f; } } } };   int N, G, E, p[20000], a[112345], b[112345]; Dinic tree;   signed main() { int S[100][100];//番号 int a, b; cin >> a >> b; memset(S, -1, sizeof(S)); string c[100]; P s, g; int sum = 2; for (int i = 0; i < a; i++) { cin >> c[i]; for (int j = 0; j < b; j++) { if (c[i][j] == 'S') { s = { i,j }; S[i][j] = 0; tree.add_edge(0, 1, 1); } else if (c[i][j] == 'T') { g = { i,j }; S[i][j] = 1; tree.add_edge(2, 3, 1); } else if (c[i][j] == 'o') { S[i][j] = sum++; tree.add_edge(S[i][j] * 2+1, S[i][j] * 2,1); } } } if (s.first == g.first || s.second == g.second) { puts("-1"); return 0; } for (int i = 0; i < a; i++) { for (int j = 0; j < b; j++) { if (S[i][j] != -1) { for (int k = i + 1; k < a; k++) { if (S[k][j] != -1) { tree.add_edge(S[i][j]*2, S[k][j]*2+1, 1); tree.add_edge(S[k][j]*2, S[i][j]*2+1, 1); } } for (int k = j + 1; k < b; k++) { if (S[i][k] != -1) { tree.add_edge(S[i][j]*2, S[i][k]*2+1, 1); tree.add_edge(S[i][k]*2, S[i][j]*2+1, 1); } } } } } cout << tree.max_flow(0, 3) << endl; }
a.cc:24:1: error: extended character   is not valid in an identifier 24 |   | ^ a.cc:30:1: error: extended character   is not valid in an identifier 30 |   | ^ a.cc:34:1: error: extended character   is not valid in an identifier 34 |   | ^ a.cc:42:1: error: extended character   is not valid in an identifier 42 |   | ^ a.cc:64:1: error: extended character   is not valid in an identifier 64 |   | ^ a.cc:85:1: error: extended character   is not valid in an identifier 85 |   | ^ a.cc:100:1: error: extended character   is not valid in an identifier 100 |   | ^ a.cc:103:1: error: extended character   is not valid in an identifier 103 |   | ^ a.cc:24:1: error: '\U000000a0' does not name a type 24 |   | ^ a.cc:30:1: error: '\U000000a0' does not name a type 30 |   | ^ a.cc:32:18: error: 'MAX_V' was not declared in this scope 32 | LL level[MAX_V]; // sからの距離 | ^~~~~ a.cc:33:17: error: 'MAX_V' was not declared in this scope 33 | LL iter[MAX_V]; // どこまで調べ終わったか | ^~~~~ a.cc:34:1: error: '\U000000a0' does not name a type 34 |   | ^ a.cc:42:1: error: '\U000000a0' does not name a type 42 |   | ^ a.cc:64:1: error: '\U000000a0' does not name a type 64 |   | ^ a.cc:85:1: error: '\U000000a0' does not name a type 85 |   | ^ a.cc:100:1: error: '\U000000a0' does not name a type 100 |   | ^ a.cc:103:1: error: '\U000000a0' does not name a type 103 |   | ^
s452237171
p03718
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int N=3e2+5; const ll inf=2e15; const ll mod=1e9+7; //题意:n*m地图 n,m<=100,起点S,终点T 'o'表示叶子,每次可以跳到同行或者同列的'o'上,问最少删掉多少个'o'使得S无法到达T? //最小割模型,先把图变为二分图,每行每列加上源点和汇点,两边点分别为1~n,1~m //对叶子'o'(x,y):x-y连接一条边 表示第x行的叶子可以跳到第y列 容量为1:表示删除(x,y)这一个点 //加上边 S->SX S-SY TX->T,TY->T 容量为inf 不能删除 //现在只要求出从S->T的最大流即可,因为最大流时的图,无增广路即,S->T不存在路径,对应的s-t割为最小割,容量最小. char s[N][N]; ll n,m,g[N][N]; ll path[N],flow[N],start,end; queue<int> q; void init() { memset(g,0,sizeof(g)); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(s[i][j]=='S') { g[0][i]=inf; g[0][n+j]=inf; } if(s[i][j]=='T') { g[i][n+m+1]=inf; g[n+j][n+m+1]=inf; } if(s[i][j]=='o') g[i][n+j]=1,g[n+j][i]=1; } } } ll bfs() { while(!q.empty()) q.pop(); memset(path,-1,sizeof(path)); path[start]=0,flow[start]=inf; q.push(start); while(!q.empty()) { int t=q.front(); q.pop(); if(t==end) break; for(int i=1;i<=n+m+1;i++) { if(i!=start && path[i]==-1 && g[t][i]) { flow[i]=min(flow[t],g[t][i]); q.push(i); path[i]=t; } } } if(path[end]==-1) return -1; return flow[end]; } ll Edmonds_Karp() { ll mx_flow=0,step,now,pre; while((step=bfs())!=-1)//找不到增广路退出 { mx_flow+=step; now=end; while(now!=start) { pre=path[now]; g[pre][now]-=step;//更新正向边容量 g[now][pre]+=step;//更新反向边(Gf走反向边 相当于在G中减小该边流量) now=pre; } } return mx_flow; } int main() { while(cin>>n>>m) { for(int i=1;i<=n;i++) scanf("%s",s[i]+1); init();//建图 start=0,end=n+m+1; ll ans=Edmonds_Karp(); if(ans>=inf) puts("-1"); else cout<<ans<<endl; } return 0; }
a.cc: In function 'll bfs()': a.cc:52:23: error: reference to 'end' is ambiguous 52 | if(t==end) | ^~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166, from a.cc:1: /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ In file included from /usr/include/c++/14/string:53, 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/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ In file included from /usr/include/c++/14/bits/algorithmfwd.h:39, from /usr/include/c++/14/bits/stl_algo.h:59, from /usr/include/c++/14/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:16:26: note: 'll end' 16 | ll path[N],flow[N],start,end; | ^~~ a.cc:64:17: error: reference to 'end' is ambiguous 64 | if(path[end]==-1) | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:16:26: note: 'll end' 16 | ll path[N],flow[N],start,end; | ^~~ a.cc:66:21: error: reference to 'end' is ambiguous 66 | return flow[end]; | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:16:26: note: 'll end' 16 | ll path[N],flow[N],start,end; | ^~~ a.cc: In function 'll Edmonds_Karp()': a.cc:74:21: error: reference to 'end' is ambiguous 74 | now=end; | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:16:26: note: 'll end' 16 | ll path[N],flow[N],start,end; | ^~~ a.cc: In function 'int main()': a.cc:92:25: error: reference to 'end' is ambiguous 92 | start=0,end=n+m+1; | ^~~ /usr/include/c++/14/valarray:1265:5: note: candidates are: 'template<class _Tp> const _Tp* std::end(const valarray<_Tp>&)' 1265 | end(const valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/valarray:1249:5: note: 'template<class _Tp> _Tp* std::end(valarray<_Tp>&)' 1249 | end(valarray<_Tp>& __va) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:106:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])' 106 | end(_Tp (&__arr)[_Nm]) noexcept | ^~~ /usr/include/c++/14/bits/range_access.h:85:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)' 85 | end(const _Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/bits/range_access.h:74:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)' 74 | end(_Container& __cont) -> decltype(__cont.end()) | ^~~ /usr/include/c++/14/initializer_list:99:5: note: 'template<class _Tp> constexpr const _Tp* std::end(initializer_list<_Tp>)' 99 | end(initializer_list<_Tp> __ils) noexcept | ^~~ a.cc:16:26: note: 'll end' 16 | ll path[N],flow[N],start,end; | ^~~
s392487876
p03718
C++
#include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> #include <iomanip> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define uniq(c) c.erase(unique(all(c)), (c).end()) #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 struct Edge { int to, cap, rev; }; #define MAX_N 30000 class Dinic { public: vector<Edge> G[MAX_N]; int level[MAX_N], iter[MAX_N]; void add_edge(int from, int to, int cap) { G[from].pb((Edge) { to, cap, (int)G[to].size() }); G[to].pb((Edge) { from, 0, (int)G[from].size() - 1 }); } void bfs(int s) { memset(level, -1, sizeof(level)); queue<int> q; level[s] = 0; q.push(s); while (!q.empty()) { int x = q.front(); q.pop(); for (Edge e : G[x]) { if (e.cap > 0 && level[e.to] < 0) { level[e.to] = level[x] + 1; q.push(e.to); } } } } int dfs(int x, int t, int f) { if (x == t) return f; for (int &i=iter[x]; i<G[x].size(); i++) { Edge &e = G[x][i]; if (e.cap > 0 && level[x] < level[e.to]) { int d = dfs(e.to, t, min(f, e.cap)); if (d > 0) { e.cap -= d; G[e.to][e.rev].cap += d; return d; } } } return 0; } int max_flow(int s, int t) { int flow = 0; while (true) { bfs(s); if (level[t] < 0) return flow; memset(iter, 0, sizeof(iter)); int f; while (true) { f = dfs(s, t, INF); if (f <= 0) break; flow += f; } } } }; int W, H; int SX, SY, TX, TY; char A[100][100]; int WI[100], HI[100]; int IN[100][100], OUT[100][100]; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> H >> W; rep(y, H) { rep(x, W) { cin >> A[x][y]; if (A[x][y] == 'S') SX = x, SY = y; if (A[x][y] == 'T') TX = x, TY = y; } } rep(i, W) WI[i] = 2*W*H + i; rep(i, H) HI[i] = 2*W*H + W + i; rep(x, W) { rep(y, H) { IN[x][y] = 2*(x*H + y); OUT[x][y] = 2*(x*H + y)+1; } } Dinic dinic; rep(x, W) { rep(y, H) { if (A[x][y] == '.') continue; // (x,y) <-> WI[x] dinic.add_edge(OUT[x][y], WI[x], INF); dinic.add_edge(WI[x], IN[x][y], INF); // (x,y) <-> HI[x] dinic.add_edge(OUT[x][y], HI[y], INF); dinic.add_edge(HI[y], IN[x][y], INF); // in -> out dinic.add_edge(IN[x][y], OUT[x][y], 1); } } int ans = dinic.max_flow(OUT[SX][SY], IN[TX][TY]); if (ans == INF) cout << -1 << "\n"; else cout << ans << "\n"; return 0; }
a.cc: In member function 'void Dinic::bfs(int)': a.cc:37:5: error: 'memset' was not declared in this scope 37 | memset(level, -1, sizeof(level)); | ^~~~~~ a.cc:11:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 10 | #include <iomanip> +++ |+#include <cstring> 11 | using namespace std; a.cc: In member function 'int Dinic::max_flow(int, int)': a.cc:73:7: error: 'memset' was not declared in this scope 73 | memset(iter, 0, sizeof(iter)); | ^~~~~~ a.cc:73:7: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
s896510277
p03718
C++
#include<cstdio> #include<queue> #include<iostream> #include<algorithm> using namespace std; const int inf=1050000000; const int maxn=217; const int maxm=20500; char c; int n,m,s,t,u,v,w,h,y,edge_cnt=1; int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn]; queue <int> q; void addedge(int u,int v,int w) { ++edge_cnt; next[edge_cnt]=first[u]; first[u]=edge_cnt; to[edge_cnt]=v; r[edge_cnt]=w; ++edge_cnt; next[edge_cnt]=first[v]; first[v]=edge_cnt; to[edge_cnt]=u; r[edge_cnt]=w; } bool bfs(){ q.push(s); fill(d+1,d+t+1,0); d[s]=1; while (!q.empty()) { int u=q.front(); q.pop(); for (int e=first[u]; e; e=next[e]) { int v=to[e]; if (d[v]==0 && r[e]>0) d[v]=d[u]+1,q.push(v); } } return d[t]>0; } int dfs(int x,int budget){ if (x==t) return budget; int ans=0; for (int &e=cur[x]; e; e=next[e]) { int v=to[e]; if (d[v]==d[x]+1 && r[e]>0) { int ret=dfs(v,min(budget,r[e])); ans += ret; r[e] -= ret; r[e^1] += ret; budget -= ret; if (budget==0) break; } } return ans; } int main(){ ios::sync_with_stdio(false); scanf("%d%d",&h,&y); n=h+y; s=n+1,t=n+2; for (int i=1; i<=h; i++) for (int j=1; j<=y; j++) { cin>>c; if (c=='S') addedge(s,i,inf),addedge(s,h+j,inf); if (c=='T') addedge(i,t,inf),addedge(h+j,t,inf); if (c=='o') addedge(i,h+j,1); } int ans=0; while (bfs()) { for (int i=1; i<=t; i++) cur[i]=first[i]; ans+=dfs(s,inf); } if (ans>=inf) ans=-1; printf("%d\n",ans); return 0; }
a.cc: In function 'void addedge(int, int, int)': a.cc:15:9: error: reference to 'next' is ambiguous 15 | next[edge_cnt]=first[u]; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/deque:62, from /usr/include/c++/14/queue:62, from a.cc:2: /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:11:27: note: 'int next [20500]' 11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn]; | ^~~~ a.cc:21:9: error: reference to 'next' is ambiguous 21 | next[edge_cnt]=first[v]; | ^~~~ /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:11:27: note: 'int next [20500]' 11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn]; | ^~~~ a.cc: In function 'bool bfs()': a.cc:33:43: error: reference to 'next' is ambiguous 33 | for (int e=first[u]; e; e=next[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:11:27: note: 'int next [20500]' 11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn]; | ^~~~ a.cc: In function 'int dfs(int, int)': a.cc:43:34: error: reference to 'next' is ambiguous 43 | for (int &e=cur[x]; e; e=next[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:11:27: note: 'int next [20500]' 11 | int cur[maxn],first[maxn],next[maxm],to[maxm],r[maxm],d[maxn]; | ^~~~
s599413785
p03718
C++
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int inf=30000; int edge[30000],next[30000],flow[30000],first[300]; int g[300],h[300]; char c[300][300]; int i,j,m,n,s,head,tail,sum_edge; inline void addedge(int x,int y,int f) { sum_edge++,edge[sum_edge]=y,flow[sum_edge]=f,next[sum_edge]=first[x],first[x]=sum_edge; return; } inline int oppedge(int x) { return ((x-1)^1)+1; } inline void buildgraph() { scanf("%d%d",&n,&m); for (i=1;i<=n;i++) scanf("%s",c[i]+1); for (i=1;i<=n;i++) for (j=1;j<=m;j++) switch (c[i][j]) { case 'S': addedge(0,i,inf),addedge(i,0,0); addedge(0,n+j,inf),addedge(n+j,0,0); break; case 'T': addedge(i,n+m+1,inf),addedge(n+m+1,i,0); addedge(n+j,n+m+1,inf),addedge(n+m+1,n+j,0); break; case 'o': addedge(i,n+j,1),addedge(n+j,i,1); break; } return; } inline int dinic_bfs() { memset(h,0,sizeof(h)); tail=1,g[tail]=0,h[g[tail]]=1; for (head=1;head<=tail;head++) for (i=first[g[head]];i!=0;i=next[i]) if ((flow[i]) && (! h[edge[i]])) tail++,g[tail]=edge[i],h[g[tail]]=h[g[head]]+1; return h[n+m+1]; } inline int dinic_dfs(int now,int cap) { if (now==n+m+1) return cap; int s=0,t=0; for (int i=first[now];i!=0;i=next[i]) if ((flow[i]) && (h[edge[i]]==h[now]+1)) { t=dinic_dfs(edge[i],min(cap,flow[i])); s=s+t,cap=cap-t; flow[i]=flow[i]-t,flow[oppedge(i)]=flow[oppedge(i)]+t; if (! cap) break; } if (cap) h[now]=0; return s; } inline void maxflow() { while (dinic_bfs()) s=s+dinic_dfs(0,inf); if (s>n*m) printf("-1"); else printf("%d",s); return; } int main() { buildgraph(); maxflow(); return 0; }
a.cc: In function 'void addedge(int, int, int)': a.cc:16:54: error: reference to 'next' is ambiguous 16 | sum_edge++,edge[sum_edge]=y,flow[sum_edge]=f,next[sum_edge]=first[x],first[x]=sum_edge; | ^~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:66, from /usr/include/c++/14/algorithm:60, from a.cc:3: /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:9:17: note: 'int next [30000]' 9 | int edge[30000],next[30000],flow[30000],first[300]; | ^~~~ a.cc: In function 'int dinic_bfs()': a.cc:54:46: error: reference to 'next' is ambiguous 54 | for (i=first[g[head]];i!=0;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:9:17: note: 'int next [30000]' 9 | int edge[30000],next[30000],flow[30000],first[300]; | ^~~~ a.cc: In function 'int dinic_dfs(int, int)': a.cc:65:38: error: reference to 'next' is ambiguous 65 | for (int i=first[now];i!=0;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:9:17: note: 'int next [30000]' 9 | int edge[30000],next[30000],flow[30000],first[300]; | ^~~~
s239962196
p03718
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; #define X first #define Y second const int M=3e4+10; const int inf=1e9; const int MOD=1e9+7; priority_queue <int> pq; struct maxflow{ int m; int st,en; int v[M][2],flow[M][2],cap[M]; int f[M],tr[M]; vector <int> e[M]; maxflow(){ m=st=en=0; } void add_edge(int x,int y,int _cap){ // cout<<x<<"->"<<y<<'\n'; ++m; v[m][0]=x;v[m][1]=y; e[x].push_back(m); e[y].push_back(m); cap[m]=_cap; flow[m][1]=_cap; flow[m][0]=0; } int q[N]; bool BFS(int st){ memset(tr,0,sizeof(tr)); int top=1,bot=1; q[1]=st; while (top<=bot){ int x=q[top++]; if (x==en) return 1; for(auto i:e[x]){ int dir=(x==v[i][1]); int y=v[i][dir^1]; if (flow[i][dir]==cap[i]||tr[y]) continue; tr[y]=i; f[y]=min(f[x],cap[i]-flow[i][dir]); q[++bot]=y; } } return 0; } void inc_flow(){ int cur=en; int ans=f[en]; while (cur!=st){ int use=tr[cur]; int dir=(cur==v[use][0]); flow[use][dir]+=ans; flow[use][dir^1]-=ans; cur=v[use][dir]; } } int answer(){ int ans=0; f[st]=inf; while (BFS(st)){ ans+=f[en]; inc_flow(); } return ans; } }mflow; int n,m; string s[105]; void prepare(){ cin>>n>>m; for(int i=0;i<n;i++) cin>>s[i]; for(int i=0;i<n;i++) for(int j=0;j<m;j++){ if (s[i][j]=='S') mflow.st=n*m+i*m+j; if (s[i][j]=='T') mflow.en=i*m+j; if (s[i][j]!='.'){ mflow.add_edge(i*m+j,i*m+j+n*m,1); mflow.add_edge(2*n*m+i,i*m+j,inf); mflow.add_edge(i*m+j+n*m,2*n*m+i,inf); mflow.add_edge(2*n*m+n+j,i*m+j,inf); mflow.add_edge(i*m+j+n*m,2*n*m+n+j,inf); } } } int main(){ prepare(); int ans=mflow.answer(); if (ans==inf) cout<<"-1"; else cout<<ans; }
a.cc:39:11: error: 'N' was not declared in this scope 39 | int q[N]; | ^ a.cc: In member function 'bool maxflow::BFS(int)': a.cc:44:9: error: 'q' was not declared in this scope; did you mean 'pq'? 44 | q[1]=st; | ^ | pq
s750267845
p03718
C++
10 10 .o...o..o. ....o..... ....oo.oo. ..oooo..o. ....oo.... ..o..o.... o..o....So o....T.... ....o..... ........oo
a.cc:1:1: error: expected unqualified-id before numeric constant 1 | 10 10 | ^~
s525145898
p03718
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; int H, W; char field[105][105]; class Dinic { int MAX_V; int INF; struct edge{ int to, cap, rev, icap, flow; }; vector< vector<edge> > G; vector<int> level; //sからの距離 vector<int> iter; //どこまで調べたか void max_flow_bfs(int s){ fill(level.begin(), level.end(), -1); queue<int> que; level[s] = 0; que.push(s); while(!que.empty()){ int v = que.front(); que.pop(); for(int i=0; i<G[v].size(); i++){ edge &e = G[v][i]; if(e.cap>0 && level[e.to]<0){ level[e.to] = level[v] + 1; que.push(e.to); } } } } int max_flow_dfs(int v, int t, int f){ if(v==t) return f; for(int &i=iter[v]; i<G[v].size(); i++){ edge &e = G[v][i]; if(e.cap>0 && level[v]<level[e.to]){ int d = max_flow_dfs(e.to, t, min(f, e.cap)); if(d>0){ e.cap -= d; G[e.to][e.rev].cap += d; e.flow += d; return d; } } } return 0; } public: Dinic(int N):MAX_V(N),G(N),level(N),iter(N){ INF = 99999999; } void add_edge(int from, int to, int cap){ G[from].push_back((edge){to, cap, G[to].size(), cap, 0}); G[to].push_back((edge){from, 0, G[from].size()-1, 0, 0}); } int get_flow(int from, int to){ //untried rep(i,G[from].size()){ if(G[from][i].to == to){ return G[from][i].flow; } } return -1; } int max_flow(int s, int t){ int flow = 0; while(true){ max_flow_bfs(s); if(level[t]<0) return flow; fill(iter.begin(), iter.end(), 0); int f; while((f = max_flow_dfs(s, t, INF))>0){ flow += f; } } } int min_cut(int s, int t, vector<int>& S, vector<int>& T){ S.clear(); T.clear(); int maxf = max_flow(s, t); for(int i=0; i<level.size(); i++){ if(level[i] >= 0) S.push_back(i); else T.push_back(i); } return maxf; } }; int main(){ cin >> H >> W; rep(i,H){ string str; cin >> str; rep(j,W){ field[i][j] = str[j]; } } Dinic dinic(1005); int s_id = -1; int t_id = -1; rep(i,H){ rep(j,W){ if(field[i][j] == 'S'){ s_id = i*W+j; field[i][j] = 'o'; } if(field[i][j] == 'T'){ t_id = i*W+j; field[i][j] = 'o'; } } } int sy = s_id/W, sx = s_id%W; int ty = t_id/W, tx = t_id%W; if(sy == ty || sx == tx){ cout << -1 << endl; return 0; } rep(i,H){ rep(j,W){ if(field[i][j] == 'o'){ rep(k,W){ if(k!=j && field[i][k] == 'o'){ dinic.add_edge(i*W+j, i*W+k); dinic.add_edge(i*W+k, i*W+j); } } rep(k,H){ if(k!=i && field[k][j] == 'o'){ dinic.add_edge(i*W+j, k*W+j); dinic.add_edge(k*W+j, i*W+j); } } } } } vector<int> S, T; cout << dinic.min_cut(s_id, t_id, S, T) << endl; return 0; }
a.cc: In member function 'void Dinic::add_edge(int, int, int)': a.cc:61:49: warning: narrowing conversion of '(&((Dinic*)this)->Dinic::G.std::vector<std::vector<Dinic::edge> >::operator[](((std::vector<std::vector<Dinic::edge> >::size_type)to)))->std::vector<Dinic::edge>::size()' from 'std::vector<Dinic::edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 61 | G[from].push_back((edge){to, cap, G[to].size(), cap, 0}); | ~~~~~~~~~~^~ a.cc:62:51: warning: narrowing conversion of '((&((Dinic*)this)->Dinic::G.std::vector<std::vector<Dinic::edge> >::operator[](((std::vector<std::vector<Dinic::edge> >::size_type)from)))->std::vector<Dinic::edge>::size() - 1)' from 'std::vector<Dinic::edge>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing] 62 | G[to].push_back((edge){from, 0, G[from].size()-1, 0, 0}); | ~~~~~~~~~~~~~~^~ a.cc: In function 'int main()': a.cc:140:27: error: no matching function for call to 'Dinic::add_edge(int, int)' 140 | dinic.add_edge(i*W+j, i*W+k); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~ a.cc:60:8: note: candidate: 'void Dinic::add_edge(int, int, int)' 60 | void add_edge(int from, int to, int cap){ | ^~~~~~~~ a.cc:60:8: note: candidate expects 3 arguments, 2 provided a.cc:141:27: error: no matching function for call to 'Dinic::add_edge(int, int)' 141 | dinic.add_edge(i*W+k, i*W+j); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~ a.cc:60:8: note: candidate: 'void Dinic::add_edge(int, int, int)' 60 | void add_edge(int from, int to, int cap){ | ^~~~~~~~ a.cc:60:8: note: candidate expects 3 arguments, 2 provided a.cc:146:27: error: no matching function for call to 'Dinic::add_edge(int, int)' 146 | dinic.add_edge(i*W+j, k*W+j); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~ a.cc:60:8: note: candidate: 'void Dinic::add_edge(int, int, int)' 60 | void add_edge(int from, int to, int cap){ | ^~~~~~~~ a.cc:60:8: note: candidate expects 3 arguments, 2 provided a.cc:147:27: error: no matching function for call to 'Dinic::add_edge(int, int)' 147 | dinic.add_edge(k*W+j, i*W+j); | ~~~~~~~~~~~~~~^~~~~~~~~~~~~~ a.cc:60:8: note: candidate: 'void Dinic::add_edge(int, int, int)' 60 | void add_edge(int from, int to, int cap){ | ^~~~~~~~ a.cc:60:8: note: candidate expects 3 arguments, 2 provided
s372444326
p03718
C++
#include<iostream> #include<queue> #include<algorithm> using namespace std; const int inf=1050000000; int h,w,s,t,edge_cnt=1,xs,xt,ys,yt; char c[110][110]; int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; int num(int x,int y){ return (x-1) * h + y; } queue <int> q; void addedge(int u,int v) { ++edge_cnt; next[edge_cnt]=first[u]; first[u]=edge_cnt; too[edge_cnt]=v; r[edge_cnt]=1; ++edge_cnt; next[edge_cnt]=first[v]; first[v]=edge_cnt; too[edge_cnt]=u; r[edge_cnt]=1; } bool bfs(){ q.push(s); fill(d+1,d+t+1,0); d[s]=1; while (!q.empty()) { int u=q.front(); q.pop(); for (int e=first[u]; e; e=next[e]) { int v=too[e]; if (d[v]==0 && r[e]>0) d[v]=d[u]+1,q.push(v); } } return d[t]>0; } int dfs(int x,int budget){ if (x==t) return budget; int ans=0; for (int &e=cur[x]; e; e=next[e]) { int v=too[e]; if (d[v]==d[x]+1 && r[e]>0) { int ret=dfs(v,min(budget,r[e])); ans += ret; r[e] -= ret; r[e^1] += ret; budget -= ret; if (budget==0) break; } } return ans; } int main(){ ios::sync_with_stdio(false); cin>>h>>w; for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) { cin>>c[i][j]; if (c[i][j]=='S') s=num(i,j),xs=i,ys=j,c[i][j]='o'; if (c[i][j]=='T') t=num(i,j),xt=i,yt=j,c[i][j]='o'; } for (int i=1; i<=h; i++) for (int j=1; j<=w; j++)if (c[i][j]=='o'){ for (int u=j; u<=w; u++) if (u!=j && c[i][u]=='o') addedge(num(i,j),num(i,u)); for (int u=i; u<=h; u++) if (u!=i && c[u][j]=='o') addedge(num(i,j),num(u,j)); } n=h*w; while (bfs()) { for (int i=1; i<=n; i++) cur[i]=first[i]; ans+=dfs(s,inf); } if (xs==xt || ys==yt) ans=-1; cout<<ans<<endl; return 0; }
a.cc: In function 'void addedge(int, int)': a.cc:15:9: error: reference to 'next' is ambiguous 15 | next[edge_cnt]=first[u]; | ^~~~ 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:8:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc:21:9: error: reference to 'next' is ambiguous 21 | next[edge_cnt]=first[v]; | ^~~~ /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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc: In function 'bool bfs()': a.cc:33:43: error: reference to 'next' is ambiguous 33 | for (int e=first[u]; e; e=next[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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc: In function 'int dfs(int, int)': a.cc:43:34: error: reference to 'next' is ambiguous 43 | for (int &e=cur[x]; e; e=next[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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~
s119895288
p03718
C++
#include<iostream> #include<queue> #include<algorithm> using namespace std; const int inf=1050000000; int h,w,s,t,edge_cnt=1,xs,xt,ys,yt; char c[110][110]; int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; int num(int x,int y){ return (x-1) * h + y; } queue <int> q; void addedge(int u,int v) { ++edge_cnt; next[edge_cnt]=first[u]; first[u]=edge_cnt; too[edge_cnt]=v; r[edge_cnt]=1; ++edge_cnt; next[edge_cnt]=first[v]; first[v]=edge_cnt; too[edge_cnt]=u; r[edge_cnt]=1; } bool bfs(){ q.push(s); fill(d+1,d+t+1,0); d[s]=1; while (!q.empty()) { int u=q.front(); q.pop(); for (int e=first[u]; e; e=next[e]) { int v=too[e]; if (d[v]==0 && r[e]>0) d[v]=d[u]+1,q.push(v); } } return d[t]>0; } int dfs(int x,int budget){ if (x==t) return budget; int ans=0; for (int &e=cur[x]; e; e=next[e]) { int v=too[e]; if (d[v]==d[x]+1 && r[e]>0) { int ret=dfs(v,min(budget,r[e])); ans += ret; r[e] -= ret; r[e^1] += ret; budget -= ret; if (budget==0) break; } } return ans; } int main(){ ios::sync_with_stdio(false); cin>>h>>w; for (int i=1; i<=h; i++) for (int j=1; j<=w; j++) { cin>>c[i][j]; if (c[i][j]=='S') s=num(i,j),xs=i,ys=j,c[i][j]='o'; if (c[i][j]=='T') t=num(i,j),xt=i,yt=j,c[i][j]='o'; } for (int i=1; i<=h; i++) for (int j=1; j<=w; j++)if (c[i][j]=='o'){ for (int u=j; u<=w; u++) if (u!=j && c[i][u]=='o') addedge(num(i,j),num(i,u)); for (int u=i; u<=h; u++) if (u!=i && c[u][j]=='o') addedge(num(i,j),num(u,j)); } n=h*w; while (bfs()) { for (int i=1; i<=n; i++) cur[i]=first[i]; ans+=dfs(s,inf); } if (xs==xt || ys==yt) ans=-1; cout<<ans<<endl; return 0; }
a.cc: In function 'void addedge(int, int)': a.cc:15:9: error: reference to 'next' is ambiguous 15 | next[edge_cnt]=first[u]; | ^~~~ 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:8:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc:21:9: error: reference to 'next' is ambiguous 21 | next[edge_cnt]=first[v]; | ^~~~ /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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc: In function 'bool bfs()': a.cc:33:43: error: reference to 'next' is ambiguous 33 | for (int e=first[u]; e; e=next[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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~ a.cc: In function 'int dfs(int, int)': a.cc:43:34: error: reference to 'next' is ambiguous 43 | for (int &e=cur[x]; e; e=next[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:44: note: 'int next [2000010]' 8 | int ans,n,first[10007],d[10007],cur[10007],next[2000010],r[2000010],too[2000010]; | ^~~~
s159176696
p03718
C++
#include<string> #include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> //#include<map> using namespace std; typedef long long int llint; #define mp make_pair #define mt make_tuple #define pub push_back #define puf push_front #define pob pop_back #define pof pop_front #define fi first #define se second #define res resize const llint mod=1000000007; const llint big=1e18; //0.... 縦 //1.... 横 //2.0.. i総合 //2.1.. j総合 //20200 s //20201 t struct edge{int to,cap,rev;}; vector<edge> G[20202]; bool used[20202]; int dfs(int v,int t,int f){ if(v==t){return f;} used[v]=true; for(int i=0;i<G[v].size();i++){ edge &e=G[v][i]; if(!used[e.to]&&e.cap>0){ int d=dfs(e.to,t,min(f,e.cap)); if(d>0){ e.cap-=d; G[e.to][e.rev].cap+=d; return d; } } } return 0; } int max_flow(int s,int t){ int flow=0; while(-1){ memset(used,0,sizeof(used)); int f=dfs(s,t,mod); if(f==0){return flow;} flow+=f; } } void add_edge(int from,int to,int cap){ edge E; E.to=to,E.cap=cap;E.rev=(int)G[to].size(); G[from].pub(E); E.to=from,E.cap=0;E.rev=(int)G[from].size()-1; G[to].pub(E); } void Radd_edge(int a,int b,int c){ add_edge(a,b,c); add_edge(b,a,c); } int main(void){ int i,j,H,W; vector<string> ike; cin>>H>>W; ike.res(H); for(i=0;i<H;i++){ cin>>ike[i]; } for(i=0;i<H;i++){ for(j=0;j<W;j++){ if(ike[i][j]!='.'){ Radd_edge(i*100+j,10000+i*100+j,1); Radd_edge(i*100+j,20000+i,10000); Radd_edge(10000+i*100+j,20100+j,10000); } if(ike[i][j]=='S'){Radd_edge(20200,i*100+j,10000);Radd_edge(20200,10000+i*100+j,10000);} if(ike[i][j]=='T'){Radd_edge(20201,i*100+j,10000);Radd_edge(20201,10000+i*100+j,10000);} } } i=max_flow(20200,20201); if(i>=10000){i=-1;} cout<<i<<endl; return 0; }
a.cc: In function 'int max_flow(int, int)': a.cc:54:17: error: 'memset' was not declared in this scope 54 | memset(used,0,sizeof(used)); | ^~~~~~ a.cc:9:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 8 | #include<cmath> +++ |+#include <cstring> 9 | //#include<map>
s244606584
p03718
C++
#include <iostream> #include <algorithm> #include <cstring> #include <string> #include <cstdio> #include <map> #include <set> #include <utility> #include <vector> #include <queue> #include <cmath> #define read(X) scanf("%d",&X); #define readLL(X) cin>>X; #define readN(N,a) for(int i=0;i<N;i++)scanf("%lld",&a[i]); #define LL long long #define FOR(x,a,b) for(int x=a;x<b;x++) #define pii pair<int,int> using namespace std; const int MAXN = 200002; /* max number of vertices - adjust */ const int MAXM = 200002; /* max number of edges - adjust */ const int INF = 1<<30; int flow; int bottleneck; int n, m, e; int s, t; int x, y, w; int p[MAXN], edge[MAXN]; int last[MAXN]; int prev[MAXM]; int to[MAXM]; int c[MAXM], f[MAXM]; /* add directed edge x->y with capacity w */ void add(int x, int y, int w) { prev[e] = last[x]; last[x] = e; to[e] = y; c[e] = w; f[e] = 0; e++; prev[e] = last[y]; last[y] = e; to[e] = x; c[e] = 0; f[e] = 0; e++; } /* find augmenting path in residual graph */ bool path(int u, int v) { queue<int> Q; int C, F; for(int i = 0; i < n; i++) p[i] = -1; Q.push(u); p[u] = u; while(!Q.empty()) { x = Q.front(), Q.pop(); //cout<<x<<endl; if(x == v) return true; for(int i=last[x]; i!=-1; i=prev[i]) { //cout<<i<<endl; y = to[i]; F = f[i]; C = c[i]; if(p[y] == -1 && C > F) { p[y] = x; edge[y] = i; Q.push(y); } } } return false; } /* send flow through augmenting path */ int send(int u, int v) { bottleneck = INF; int x, y, index, sym; y = v; while(p[y] != y) { x = p[y]; index = edge[y]; bottleneck = (bottleneck > c[index]-f[index] ? c[index]-f[index] : bottleneck); y = x; } y = v; while(p[y] != y) { x = p[y]; index = edge[y]; f[index] += bottleneck; f[index^1] -= bottleneck; y = x; } return bottleneck; } int N,M; char lho[111][111]; int nid[111][111]; int main(){ read(N); read(M); n,m=0; /* build graph */ memset(last, -1, sizeof(last)); FOR(i,0,N){ scanf("%s",lho[i]); } //cout<<"dah"<<endl; FOR(i,0,N) FOR(j,0,M){ if (lho[i][j]=='.') continue; if (lho[i][j]=='S'){ s = n+1; } if (lho[i][j]=='T'){ t = n; } if (lho[i][j]!='.'){ n+=2; add(n-2, n-1,1); m++; nid[i][j] = n-2; } } //cout<<"wut "<<n<<" "<<m<<endl; FOR(i,0,N) FOR(j,0,M){ if (lho[i][j] != '.'){ FOR(k,0,N){ if (i==k) continue; if (lho[k][j]!='.'){ m++; add(nid[i][j] + 1, nid[k][j], 1); } if (lho[i][j]=='S' && lho[k][j]=='T') { cout<<-1<<endl; return 0; } } FOR(k,0,M){ if (j==k) continue; if (lho[i][k]!='.'){ m++; add(nid[i][j] + 1, nid[i][k], 1); } if (lho[i][j]=='S' && lho[i][k]=='T') { cout<<-1<<endl; return 0; } } } } //cout<<"wut "<<s<<" "<<t<<endl; flow = 0; while(path(s, t)){ //cout<<"hah "<<flow<<endl; flow += send(s, t); } printf("%d\n", flow); return 0; }
a.cc: In function 'void add(int, int, int)': a.cc:37:5: error: reference to 'prev' is ambiguous 37 | { prev[e] = last[x]; | ^~~~ 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:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)' 244 | prev(_BidirectionalIterator __x, typename | ^~~~ a.cc:31:5: note: 'int prev [200002]' 31 | int prev[MAXM]; | ^~~~ a.cc:43:5: error: reference to 'prev' is ambiguous 43 | prev[e] = last[y]; | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)' 244 | prev(_BidirectionalIterator __x, typename | ^~~~ a.cc:31:5: note: 'int prev [200002]' 31 | int prev[MAXM]; | ^~~~ a.cc: In function 'bool path(int, int)': a.cc:65:37: error: reference to 'prev' is ambiguous 65 | for(int i=last[x]; i!=-1; i=prev[i]) | ^~~~ /usr/include/c++/14/bits/stl_iterator_base_funcs.h:244:5: note: candidates are: 'template<class _BidirectionalIterator> constexpr _BidirectionalIterator std::prev(_BidirectionalIterator, typename iterator_traits<_Iter>::difference_type)' 244 | prev(_BidirectionalIterator __x, typename | ^~~~ a.cc:31:5: note: 'int prev [200002]' 31 | int prev[MAXM]; | ^~~~
s977322746
p03718
C++
#include <iostream> #include <stdio.h> #include <math.h> #include <string.h> #include <time.h> #include <stdlib.h> #include <string> #include <bitset> #include <vector> #include <set> #include <map> #include <queue> #include <algorithm> #include <sstream> #include <stack> #include <iomanip> using namespace std; #define pb push_back #define mp make_pair typedef pair<int,int> pii; typedef long long ll; typedef double ld; typedef vector<int> vi; #define fi first #define se second #define fe first #define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);} #define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);} #define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);} #define es(x,e) (int e=fst[x];e;e=nxt[e]) #define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e]) #define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");} #define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");} #define SZ 666666 typedef long long ll; int fst[SZ],nxt[SZ],vb[SZ],cap[SZ],ff[SZ],M=1,N=0; #define ad_de ad_dl void _ad_dl(int a,int b,int c) {++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;cap[M]=c;} void ad_dl(int a,int b,int c) {_ad_dl(a,b,c); _ad_dl(b,a,0);} int S,T,q[SZ],d[SZ]; bool bfs() { memset(d,-1,4*(N+1)); d[T]=0; q[1]=T; int h=1,t=2; while(h!=t) { int cur=q[h++]; for(int e=fst[cur];e;e=nxt[e]) { int b=vb[e]; if(d[b]==-1&&cap[e^1]) { d[b]=d[cur]+1, q[t++]=b; if(b==S) return 1; //这是玄学 } } } return d[S]!=-1; } int dfs(int x,int f) { if(f<=0) return 0; if(x==T) return f; int ca=0; for(int& e=fst[x];e;e=nxt[e]) //当前弧优化 { int b=vb[e]; if(d[b]+1!=d[x]) continue; int w=dfs(b,(cap[e]<f-ca)?cap[e]:(f-ca)); cap[e]-=w; cap[e^1]+=w; ca+=w; if(ca==f) break; } if(!ca) d[x]=-1; //另一个优化 return ca; } #define inf 2e9+3 int dinic() { int ans=0; memcpy(ff,fst,4*(N+1)); while(bfs()) { //当前弧优化 ans+=dfs(S,inf); memcpy(fst,ff,4*(N+1)); } return ans; } int h,w,p[103][103][2],a[103],b[103]; char tmp[103]; int main() { scanf("%d%d\n",&h,&w); for(int i=1;i<=h;i++) a[i]=++N; for(int i=1;i<=w;i++) b[i]=++N; for(int i=1;i<=h;i++) { gets(tmp); for(int j=1;j<=w;j++) { if(tmp[j-1]=='.') continue; p[i][j][0]=++N; p[i][j][1]=++N; ad_dl(p[i][j][1],a[i],1e9); ad_dl(a[i],p[i][j][0],1e9); ad_dl(p[i][j][1],b[j],1e9); ad_dl(b[j],p[i][j][0],1e9); if(tmp[j-1]=='S') { S=N; continue; } if(tmp[j-1]=='T') { T=N-1; continue; } ad_dl(N-1,N,1); } } int ans=dinic(); if(ans>h*w) ans=-1; printf("%d\n",ans); }
a.cc: In function 'int main()': a.cc:99:17: error: 'gets' was not declared in this scope; did you mean 'getw'? 99 | gets(tmp); | ^~~~ | getw