1 条题解

  • 1
    @ 2026-1-21 18:28:37
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pii;
    #define MP(a,b) make_pair(a,b)
    int main()
    {
    	ios::sync_with_stdio(false);
    	cin.tie(0);
    	int n, s, m;
    	cin >> n >> s >> m;
    	vector<int> moves(m);
    	for (int i = 0; i < m; ++i) {
    		cin >> moves[i];
    	}
    	vector<vector<long long>> p(n + 1);
    	for (int i = 1; i <= n; ++i) {
    		int t_i;
    		cin >> t_i;
    		p[i].resize(t_i);
    		for (int j = 0; j < t_i; ++j) {
    			cin >> p[i][j];
    		}
    	}
    	vector<int> cnt(n + 1, 0);
    	long long ans = 0;
    	int pos = s;
    	cnt[pos]++;
    	if (cnt[pos] <= p[pos].size()) {
    		ans += p[pos][cnt[pos] - 1];
    	}
    	for (int move : moves) {
    		if (move == 1) {
    			pos++;
    			if (pos > n) pos = 1;
    		} else { 
    			pos--;
    			if (pos < 1) pos = n;
    		}
    		cnt[pos]++;
    		if (cnt[pos] <= p[pos].size()) {
    			ans += p[pos][cnt[pos] - 1];
    		}
    	}
    	cout << ans << endl;
    
    	return 0;
    }
    
    • 1

    信息

    ID
    12004
    时间
    1000ms
    内存
    512MiB
    难度
    3
    标签
    递交数
    0
    已通过
    0
    上传者