Submission #523975

# Submission time Handle Problem Language Result Execution time Memory
523975 2022-02-08T13:41:05 Z tube5429 Parametriziran (COCI19_parametriziran) C++14
110 / 110
1165 ms 42960 KB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define REP(a) F0R(_,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rsz resize
#define pb push_back
#define f first
#define s second
#define pf push_front
#define ft front()
#define bk back()
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define tcT template<class T
#define tcTU tcT, class U
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using str = string;
using vs = vector<str>;
using db = double;
using pl = pair<ll,ll>;
using pd = pair<db,db>;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;
tcTU> using PR = pair<T,U>;

const int MOD = 1e9+7;
const ll INF = 1e18;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1};

constexpr int bits(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }
constexpr bool onbit(int msk, int i) { return msk>>i&1; }
constexpr ll p2(int x) { return 1LL<<x; }
constexpr int pct(int x) { return __builtin_popcount(x); }
constexpr int lg2(int x) { return x == 0 ? 0 : 31 - __builtin_clz(x); }; //int only

tcT> bool ckmin(T&a, const T&b) { return b < a ? a = b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) { return b > a ? a = b,1 : 0; }

ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); }
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } 

tcTU> T fstTrue(T lo, T hi, U f) {
	hi++; assert(lo <= hi);
	while (lo < hi) {
		T mid = lo+(hi-lo)/2;
		f(mid) ? hi = mid : lo = mid+1; 
	} 
	return lo;
}
tcTU> T lstTrue(T lo, T hi, U f) {
	lo--; assert(lo <= hi);
	while (lo < hi) {
		T mid = lo+(hi-lo+1)/2;
		f(mid) ? lo = mid : hi = mid-1;
	} 
	return lo;
}

tcT> void remDup(V<T> &v) {
	sort(all(v)); v.erase(unique(all(v)), end(v)); }
void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if(sizeof...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

void setPrec() { cout << fixed << setprecision(16); }
void setIO(string NAME = "") {
	cin.tie(0)->sync_with_stdio(0);
	setPrec();
	if(sz(NAME)) {
		freopen((NAME + ".in").c_str(),"r",stdin);
		freopen((NAME + ".out").c_str(),"w",stdout);
	}
}

int N,M;
ll ans = 0;
map<int,int> mp[1<<6][1<<6];

void solve() {
	cin>>N>>M;
	F0R(i,N) {
		str S;
		cin>>S;
		int msk1 = 0;
		F0R(j,M) if(S[j] != '?') msk1 |= 1<<j;
		int tmp[64];
		fill(tmp, tmp+64, -1);
		F0R(msk2, p2(M)) if((msk2 & msk1) == msk2) {
			int h = 0;
			for(int j = 0, p = 1; j<M ; j++, p*=26) {
				if(onbit(msk2, j)) {
					h += p*(S[j] - 'a');
				}
			}
			tmp[msk2] = h;
		}
		F0R(msk2, p2(M)) {
			int and_msk = msk2 & msk1;
			int h = tmp[and_msk];
			if(mp[msk2][and_msk].count(h)) ans += mp[msk2][and_msk][h];
		}
		F0R(msk2, p2(M)) if(tmp[msk2] >= 0) mp[msk1][msk2][tmp[msk2]]++;
	}
	cout << ans << nl;

}

int main() {
   setIO();

	int t=1;
	//cin>>t;
	while(t-->0) {
		solve();
	}
 
	return 0;
}

Compilation message

parametriziran.cpp: In function 'void setIO(std::string)':
parametriziran.cpp:93:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |   freopen((NAME + ".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parametriziran.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |   freopen((NAME + ".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 612 KB Output is correct
2 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 588 KB Output is correct
2 Correct 17 ms 688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1224 KB Output is correct
2 Correct 19 ms 772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1084 KB Output is correct
2 Correct 36 ms 1600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 5644 KB Output is correct
2 Correct 21 ms 816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 294 ms 10060 KB Output is correct
2 Correct 25 ms 856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 398 ms 18020 KB Output is correct
2 Correct 237 ms 8652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 28416 KB Output is correct
2 Correct 35 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1165 ms 42960 KB Output is correct
2 Correct 556 ms 21484 KB Output is correct